Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: initialization of unions Message-ID: <8864@utzoo.UUCP> Date: Sat, 31-Oct-87 19:20:08 EST Article-I.D.: utzoo.8864 Posted: Sat Oct 31 19:20:08 1987 Date-Received: Sat, 31-Oct-87 19:20:08 EST References: <165600017@uiucdcsb> <4237@ccv.bbn.COM>, <1936@killer.UUCP> Organization: U of Toronto Zoology Lines: 45 > > ...unions are initialized > > as if you were initializing their first element... > > I've never understood why this is the case. Is there some reason I'm > overlooking why the compiler couldn't let you cast it to one of the > following elements? Oh oh. This is another one of those subjects that tends to produce long flaming debates, with increasingly elaborate "solutions" proposed and vigorously championed by people who have never used or implemented them. As I understand it (I do not speak for X3J11), the main reason that the ANSI draft says *anything* about the matter is a desire to have some sort of well-defined value in a static union variable at startup time. While there is general agreement that a more flexible approach could be useful at times, it falls to the usual objections: there is no dire need for it and no implementation experience with it. The first-element approach, by the way, *is* used in some existing implementations and has worked all right (i.e. it's better than nothing). Using casts for this is thoroughly ugly, incidentally -- it may *look* like a minimal solution, but it introduces a major special case into the language because it is now the only place where casts are mandatory and the usual implicit conversions are not applicable. (Relaxing either of these rules leads to other problems.) If you have a wonderful idea on the matter, remember that ANSI standards do come up for revision regularly. You are much too late to influence the current standardization effort, but it's time to get moving if you hope to get your idea into the next revision (which is maybe 5 years away). What you should do is: (a) implement your idea in your favorite C compiler (b) get a fair number of users using the resulting compiler (c) get feedback from them on how useful the feature is and whether it causes other problems (d) using that information as ammunition, prepare a formal proposal in time for the revision process No, you cannot omit step (a); nobody will take the idea seriously unless you have DEMONSTRATED its usefulness (as opposed to speculating about it). In C, not some other language. Better start now, (a) and (b) will take time. -- PS/2: Yesterday's hardware today. | Henry Spencer @ U of Toronto Zoology OS/2: Yesterday's software tomorrow. | {allegra,ihnp4,decvax,utai}!utzoo!henry