Compatibility of textually identical structs/unions

J. Stephen Adamczyk jsa at edg1.UUCP
Tue Dec 6 02:27:10 AEST 1988


Is the following legal, according to the May 13 (88-001) draft?

struct {int a;} v1;
struct {int a;} v2 = {1};

void f() {
  v1 = v2;     /* <--- Are the structs compatible? */
}

For the assignment to be legal, the two struct types have to be
compatible.  To be compatible, they have to be "the same" (3.1.2.6).
According to 3.5.2.1 (semantics), "The presence of a struct-declaration-list
in a struct-or-union-specifier declares a new type, within a translation
unit."  Since I can't find any other section that says that the two
structs above are the same, I conclude that the two struct types are
incompatible, and therefore the assignment is not allowed.

I know that 3.1.2.6 says that "two structure, union, or enumeration
types declared in separate translation units are compatible if they have
the same number of members, the same member names, and compatible member
types".  However, this says nothing about types within one translation
unit.

Any thoughts?

Steve Adamczyk



More information about the Comp.std.c mailing list