Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.lang.c Subject: Does ANSI prohibit assignments between overlapping union components? Message-ID: <21694:03:07:21@stealth.acf.nyu.edu> Date: 17 Feb 90 03:07:22 GMT Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 21 Try this program on your favorite compiler: #include struct str { char c[20]; } ; static struct str test; static union { struct { void *v; struct str s; } c; struct str s; } u; static char c = '\0'; /* don't-crash kludge */ main() { int i; for (i = 0;i < 15;i++) test.c[i] = 'a' + i; u.s = test; puts(u.s.c); u.c.s = u.s; puts(u.c.s.c); u.s = u.c.s; puts(u.s.c); } It looks valid to me: after u.s = test, u.s is active, so accessing u.s is fine; then after u.c.s = u.s, u.c.s is active, so accessing u.c.s is fine; and so on. Is there an ANSI rule prohibiting this? If not, quite a few supposedly conformant compilers are broken. ---Dan