Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Union initialization Message-ID: <1989Feb27.165348.16099@utzoo.uucp> Organization: U of Toronto Zoology References: <816@atanasoff.cs.iastate.edu> <16019@mimsy.UUCP> <51116@yale-celray.yale.UUCP> <609@maths.tcd.ie> Date: Mon, 27 Feb 89 16:53:48 GMT In article <609@maths.tcd.ie> ch@maths.tcd.ie (Charles Bryant) writes: >[proposal in which compiler guesses which member based on type of initializer >expression] > >Perhaps this would be too much of a special case for the compiler... It's too much of a special case for the language designer, too, I'm afraid. This particular suggestion always seems to come up. It doesn't work very well. How do you initialize a struct inside a union? (Cast to the struct type? Now we have a unique situation in which such casts are legal.) What about a union inside the union? Is a string an initializer for a "char *" or a "char []"? Do implicit conversions get done? (If so, chaos. If not, we now have a unique situation in which they aren't.) If there are both int and long members, which one gets initialized if the initializer is, say, 75000 (the type of which is implementation-dependent)? Is the cast mandatory? (If so, we now have a unique etc. etc.) There are just too many problems with guessing member based on type. It really has to be done by name or position. -- The Earth is our mother; | Henry Spencer at U of Toronto Zoology our nine months are up. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu