struct initializer efficiency

L

Laurent Deniau

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
g(&a);
}

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top