Handling of untagged structures by the C compiler
Andreas Kaiser
kaiser at ananke.stgt.sub.org
Sat Sep 22 17:08:05 AEST 1990
In a message of <Sep 20 21:57>, Vox Populi ) (ravim at gtenmc.UUCP (Ravi K Mandava ) writes:
VP)> 4 #define ST struct { int i; }
VP)> 8 ST *a;
VP)> 12 if ((a = (ST *)malloc(sizeof(ST))) == NULL)
VP)> It appears that for every untagged structure declaration/typecast, the
VP)> compiler generates a unique tag internally and does not bother to
VP)> check for equivalence of the previously encountered structures.
According to ANSI, two structures are only compatible, if they have the same
"tagged type". Two identically declared structures are incompatible.
VP)> [As for myself, I always try to use typedefs or tags for structures.
VP)> I happened to come across this problem while bug-fixing someone
VP)> else's code. So please no chidings for writing bad code :-) ]
VP)> Or is it that this limitation is only with this particular compiler?
Some very old C compilers (the original Ritchie compiler for PDP-11) do not care
about structure types at all. It was possible to write code like this (found in
UNIX Version 6):
register int i;
struct { char high, low; };
.... i.high ....
--
:::::::::::::::::::: Internet: kaiser at ananke.stgt.sub.org
:: Andreas Kaiser :: Fidonet: 2:507/18.7206 (+ 2:509/5.2512)
::::::::::::::::::::
More information about the Comp.lang.c
mailing list