Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: Union type conversions Message-ID: <529@philmds.UUCP> Date: 26 Jun 88 20:44:54 GMT References: <5754@bloom-beacon.MIT.EDU> <1988Jun16.182158.2424@utzoo.uucp> <231@gannet.cl.cam.ac.uk> Reply-To: leo@philmds.UUCP (L.J.M. de Wit) Organization: Philips I&E DTS Eindhoven Lines: 32 In article <231@gannet.cl.cam.ac.uk> am@cl.cam.ac.uk (Alan Mycroft) writes: |In article <1988Jun16.182158.2424@utzoo.uucp> henry@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).