comparing structures: problems with unions
Andrew Klossner
andrew at orca.UUCP
Mon Mar 26 14:42:11 AEST 1984
"Another solution would be to clear the unused parts of the
union wherever a store is done. In many cases (admittedly not
all) this would be very cheap."
In some cases it can't be done at all:
struct {
union {char c; double d;} u;
} structure;
fill_char(pc) char *pc; {*pc = ~0;}
main() {
...
fill_char(&(structure.u.c));
...
}
The code generated for "fill_char" has no way of knowing that the
character to which it's been given a pointer is a member of a larger
union, the excess of which must be cleared.
-- Andrew Klossner (decvax!tektronix!orca!andrew) [UUCP]
(orca!andrew.tektronix at rand-relay) [ARPA]
More information about the Comp.lang.c
mailing list