Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: Union initialization Message-ID: <437@lakart.UUCP> Date: 21 Feb 89 15:41:23 GMT References: <51116@yale-celray.yale.UUCP> Organization: Lakart Corporation, Newton, MA Lines: 39 From article <51116@yale-celray.yale.UUCP>, by wald-david@CS.YALE.EDU (david wald): >>u.f is 0.0, and u.i is indeterminte. You may write >> >> union { float f; int i; } u = { 1.0 }; >> >>to set u.f, but you cannot initialise u.i since it is not the first >>member. > > I wonder... > > Yes, this question deals with some hypothetical C' or C+=2 (not quite D, > since it's a language extension rather than a revision), but... > > Would it make the syntax more ambiguous to have allowed > > union { float f; int i; } u.i = {1}; Try: union { float f; int i; char *c; } u[3] = { { 1.0 ; ; }, /* could also be { 1.0 } - trailing ; are optional */ { ; 76 ; }, /* ditto: { ; 76 } would also be OK */ { ; ; "STUG" } }; Not ambiguous at all - it is left as an excercise to the reader to figure out what is happening. If you don't like the overloaded ';' then I suggest you start bitching about ',' - that is overloaded far worse. :-P BTW ....= { 1.0 ; 76 ; }, ..... WOULD NOT BE ALLOWED - it would generate some sort of complaint. -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+