Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watmath.UUCP Path: utzoo!watmath!kpmartin From: kpmartin@watmath.UUCP (Kevin Martin) Newsgroups: net.lang.c Subject: Re: Standard for union initialization? Message-ID: <10884@watmath.UUCP> Date: Sun, 13-Jan-85 22:32:07 EST Article-I.D.: watmath.10884 Posted: Sun Jan 13 22:32:07 1985 Date-Received: Mon, 14-Jan-85 04:24:14 EST References: <6995@brl-tgr.ARPA> <7004@brl-tgr.ARPA> <6847@watdaisy.UUCP> Reply-To: kpmartin@watmath.UUCP (Kevin Martin) Organization: U of Waterloo, Ontario Lines: 36 Summary: >Why not fix the syntax of that scheme and use its semantics: > >union { >foo; > bar; > mumble; >} baz = (type3) ; > >Suppose the same type is duplicated in the union, e.g. suppose type3 is >the same as type1 and the compiler doesn't know whether to initialize >foo or mumble? Let the compiler choose whichever valid one it wishes; >the result would be equivalent. >This would not make the language any messier; it is better than many >other examples of casts. And it would be useful, and it would not break >existing programs. >-- Norman Diamond This only works if you either extend the syntax to allow "casting" of aggregate initializers, or if you *still* don't allow initialization of a union of structures. Either way, this is less clear than an initializer of the form element = value e.g. union { foo; bar; mumble; }baz = mumble = ; Since can be an expression in C already, you might find that your compiler's grammar already allows this, and it is only detected as an error after further analysis. Of course, if the "element =" is absent, the first element could be initialized. Similarly for the implicit zeroing of un-initialized static storage. Kevin Martin, UofW Software Development Group.