cast'ing unions
David Riches
dsr at stl.stc.co.uk
Fri Aug 11 18:35:41 AEST 1989
Here's a posting for a friend, replies to ME please:-
------
I have a question regarding the "union" construct in the C programming language
which I need answering urgently.
Consider the following union construct :
union
{
int i ;
float f ;
char* c ;
}
UNION ;
...
...
UNION u ;
u.i = 1 ;
Is it possible in C to typecast from an instance of the union to a variable
having the same type as one of the component fields of the union :
ie float num = (float) u ;
I tried the above but got compiler errors. Am I doing the typecast wrong,
or do I need to use another method to achieve the above, or is it not
possible to do the typecast directly ??
Dave Riches
PSS: dsr at stl.stc.co.uk
ARPA: dsr%stl.stc.co.uk at earn-relay.ac.uk
Smail: Software Design Centre, (Dept. 103, T2 West),
STC Technology Ltd., London Road,
Harlow, Essex. CM17 9NA. England
Phone: +44 (0)279-29531 x2496
More information about the Comp.lang.c
mailing list