Union type conversions

Leo de Wit leo at philmds.UUCP
Mon Jun 27 06:44:54 AEST 1988


In article <231 at gannet.cl.cam.ac.uk> am at cl.cam.ac.uk (Alan Mycroft) writes:
|In article <1988Jun16.182158.2424 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
||| So what it boils down to, is whether casting into a union type is
||| legal and portable...
||
||No.  You have to use the temporary union variable and assign to one of
||its members, as in your second example.
|
|Yes, but have you ever seen a compiler which deals with this efficiently?
|(Not to mention the human overhead.)

Yep, I see 'em every day. A good compiler SHOULD handle this
efficiently; the temp. variable would get optimized away (not being
used elsewhere). As far as the overhead is conceirned , this seems the
same argument that programming languages handled when 'making it
easier' for the programmer by

    1) AUTOMATIC declaration (and even initialization) of variables in
       FORTRAN,BASIC.
    2) AUTOMATIC declaration of types in C (functions becoming int, 
       parameters becoming int).
    3) AUTOMATIC casting of ints to pointers in C (the compiler should
       at least warn you when doing so; not all do).

The gain that you might have from these features you loose - and more
than that - spending your time to find an AUTOMATICcaly introduced bug.
Pity your debugger can't solve it AUTOMATICALly.

It seems that you'd rather have a broken compiler than take the trouble
to type some more characters?

    Leo    (join the union).



More information about the Comp.lang.c mailing list