Union initialization
Henry Spencer
henry at utzoo.uucp
Tue Feb 28 02:53:48 AEST 1989
In article <609 at maths.tcd.ie> ch at 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 at zoo.toronto.edu
More information about the Comp.lang.c
mailing list