Path: utzoo!attcan!uunet!mcvax!ukc!etive!aiva!richard
From: richard@aiva.ed.ac.uk (Richard Tobin)
Newsgroups: comp.lang.c
Subject: Re: Union type conversions
Message-ID: <494@aiva.ed.ac.uk>
Date: 7 Jul 88 19:40:59 GMT
References: <5754@bloom-beacon.MIT.EDU> <1988Jun16.182158.2424@utzoo.uucp> <231@gannet.cl.cam.ac.uk>
Reply-To: richard@uk.ac.ed.aiva (Richard Tobin)
Organization: Bannerman's Bar, Cowgate, Edinburgh
Lines: 35

>>> 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?

Indeed I have.  It's gcc (of course).  At least, it works well in this 
simple case:

main()                                    _main:                     
{					          link a6,#-2 
    int i = f();			          jbsr _f 
    char c; 
 
    { 
        union {int i; char c[4];} u; 
        u.i = i;			          moveb d0,a6@(-2) 
        c = u.c[3]; 
    } 
						  pea a6@(-2) 
    g(&c);					  jbsr _g 
}						  unlk a6 
						  rts 
>(Not to mention the human overhead.)

Doesn't solve that of course.

-- Richard

-- 
Richard Tobin,                         JANET: R.Tobin@uk.ac.ed             
AI Applications Institute,             ARPA:  R.Tobin%uk.ac.ed@nss.cs.ucl.ac.uk
Edinburgh University.                  UUCP:  ...!ukc!ed.ac.uk!R.Tobin