Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!uunet!mcvax!ukc!stl!dsr From: dsr@stl.stc.co.uk (David Riches) Newsgroups: comp.lang.c Subject: cast'ing unions Message-ID: <2189@stl.stc.co.uk> Date: 11 Aug 89 08:35:41 GMT Sender: news@stl.stc.co.uk Reply-To: dsr@stl.stc.co.uk (David Riches) Organization: STC Technology Limited, London Road, Harlow, Essex, UK Lines: 37 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@stl.stc.co.uk ARPA: dsr%stl.stc.co.uk@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