O
Oliver Charlesworth
I originally posted this on Stack Overflow
(http://stackoverflow.com/questions/2904668/compatible-types-and-structures-in-c),
but I'm not sure there was a definitive answer, so trying my luck here!
Whilst some agreed that this "should" be legal, others suggested it
wasn't because the structures were anonymous. However, I can't see such
a preclusion in the spec.
Any help appreciated.
(http://stackoverflow.com/questions/2904668/compatible-types-and-structures-in-c),
but I'm not sure there was a definitive answer, so trying my luck here!
I have the following code:
int main(void)
{
struct { int x; } a, b;
struct { int x; } c;
struct { int x; } *p;
b = a; /* OK */
c = a; /* Doesn't work */
p = &a; /* Doesn't work */
return 0;
}
which fails to compile under GCC (3.4.6), with the following error:
test.c:8: error: incompatible types in assignment
test.c:9: warning: assignment from incompatible pointer type
Now, from what I understand (admittedly from the C99 standard), is that a and c should be compatible types, as they fulfill all the criteria in section 6.2.7, paragraph 1. I've tried compiling with std=c99, to no avail.
Presumably my interpretation of the standard is wrong?
Whilst some agreed that this "should" be legal, others suggested it
wasn't because the structures were anonymous. However, I can't see such
a preclusion in the spec.
Any help appreciated.