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; }; // example could take different types with
less/more fields.
extern void g(const struct A*);
// 1st case, C99
void f1(int a, int b, int c) {
g(&(struct A*){ a,b,c }); // compound litteral
}
// 2nd case, C99
void f2(int a, int b, int c) {
struct A a = { a,b,c }; // non-constant struct initializer
g(&a);
}
// 3rd case, C89
void f3(int a, int b, int c) {
struct A a;
a.a = a, a.b = b, a.c = c; // field assignment
g(&a);
}
gcc generates the same code for the three cases. Would it be naive to
assume this behavior from a C compiler?
a+, ld.
the following three code do not have the same efficiency (both space
and time):
struct A { int a,b,c; }; // example could take different types with
less/more fields.
extern void g(const struct A*);
// 1st case, C99
void f1(int a, int b, int c) {
g(&(struct A*){ a,b,c }); // compound litteral
}
// 2nd case, C99
void f2(int a, int b, int c) {
struct A a = { a,b,c }; // non-constant struct initializer
g(&a);
}
// 3rd case, C89
void f3(int a, int b, int c) {
struct A a;
a.a = a, a.b = b, a.c = c; // field assignment
g(&a);
}
gcc generates the same code for the three cases. Would it be naive to
assume this behavior from a C compiler?
a+, ld.