Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!cfctech!teemc!ka3ovk!tgate!felix!arcturus!evil From: evil@arcturus.UUCP (Wade Guthrie) Newsgroups: comp.lang.c Subject: Re: Type punning in C Message-ID: <6310@arcturus> Date: 18 Oct 89 21:26:48 GMT References: <475@idacrd.UUCP> <11242@smoke.BRL.MIL> <605@maytag.waterloo.edu> Organization: Rockwell International, Anaheim, CA Lines: 35 >In article <11242@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: However, C does provide "union" types that can be used for such purposes. Load the bit pattern into the integer union member and extract it via the floating-point member. lhf@aries5.uucp (Luiz H de Figueiredo) writes: Provided both members have the same size! Otherwise, try union { float f; unsigned char b[sizeof(float)]; }; I thought that the standard said (as opposed to what I remember reading in K&R I) that members of unions do NOT have to have zero offset? In this case, none of the above work (and, BTW, breaks a lot of existing code). Do I completely misunderstand what the standard said, or is the stuff above just not portable to ANSI conformant compilers (God, I didn't mean for that to sound as snotty as it did -- please take that as a neophyte asking an innocent question). Wade Guthrie evil@arcturus.UUCP Rockwell International Anaheim, CA (Rockwell doesn't necessarily believe / stand by what I'm saying; how could they when *I* don't even know what I'm talking about???)