N
Neil Zanella
Hello,
In C++ AFAIK structure assignment copies every data member element by
element. This rule also works with the gcc 3.2.2 C compiler and even
works when one of the members is a union as in the following example
but I would like to know whether this is a gcc extension or whether
it's actually part of the C99 standard. Did previous C standards
allow this?
#include <stdio.h>
struct Foo { int a; int b; union { int x; float y; } z; };
int main(void) {
struct Foo hello = { 1, 2 }; /* OK */
hello.z.y = 1.1; /* OK */
printf("%f\n", hello.z.y); /* OK */
struct Foo hell = hello; /* OK */
printf("%d\n", hell.a); /* OK */
printf("%d\n", hell.b); /* OK */
printf("%f\n", hell.z.y); /* OK */
return 0;
}
Thanks,
Neil
In C++ AFAIK structure assignment copies every data member element by
element. This rule also works with the gcc 3.2.2 C compiler and even
works when one of the members is a union as in the following example
but I would like to know whether this is a gcc extension or whether
it's actually part of the C99 standard. Did previous C standards
allow this?
#include <stdio.h>
struct Foo { int a; int b; union { int x; float y; } z; };
int main(void) {
struct Foo hello = { 1, 2 }; /* OK */
hello.z.y = 1.1; /* OK */
printf("%f\n", hello.z.y); /* OK */
struct Foo hell = hello; /* OK */
printf("%d\n", hell.a); /* OK */
printf("%d\n", hell.b); /* OK */
printf("%f\n", hell.z.y); /* OK */
return 0;
}
Thanks,
Neil