Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > struct initializer efficiency

Thread Tools

struct initializer efficiency

Laurent Deniau
Posts: n/a
I was wondering if there is any good reason (semantic) to assume that
the following three code do not have the same efficiency (both space
and time):

struct A { int a,b,c; }; // could other types than int and with less/
more fields.
void g(struct A*);

// 1st case, C99
void f(int a, int b, int c) {
g(&(struct A*){ a,b,c }); // compound litteral

// 2nd case, C99
void f(int a, int b, int c) {
struct A a = { a,b,c }; // non-constant struct initializer

// 3rd case, C89
void f(int a, int b, int c) {
struct A a;
= { a,b,c }; // non-constant struct initializer

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Re: initializer list of the struct Richard C++ 0 10-20-2009 02:03 AM
struct initializer efficiency and portability Laurent Deniau C Programming 1 08-28-2007 03:22 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
struct initializer { 0 } M Kumar C Programming 2 09-28-2003 06:17 PM