Union type conversions
Richard Tobin
richard at aiva.ed.ac.uk
Fri Jul 8 05:40:59 AEST 1988
>>> 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 at uk.ac.ed
AI Applications Institute, ARPA: R.Tobin%uk.ac.ed at nss.cs.ucl.ac.uk
Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin
More information about the Comp.lang.c
mailing list