Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!mentor.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: Type punning in C Summary: There are problems with this Message-ID: <1647@l.cc.purdue.edu> Date: 10 Oct 89 14:25:15 GMT References: <475@idacrd.UUCP> <2165@dataio.Data-IO.COM> Followup-To: comp.lang.c Organization: Purdue University Statistics Department Lines: 31 In article <2165@dataio.Data-IO.COM>, bright@Data-IO.COM (Walter Bright) writes: > In article <475@idacrd.UUCP> desj@idacrd.UUCP (David desJardins) writes: | < Does anyone have any ideas on how one should go about converting an | > Try a union: > union blah { int i; float f; } x; > x.f = f; > /* now manipulate x.i */ ....................... | < int i; | < float x; | < * (int *) & x = i; | > Not at all. It's a pretty much standard and trivial optimization to > convert *(int*)&x=i into MOV X,I. Feel free to use it, with the caveat > that float format is not the same from machine to machine. I've done > it many times to do special manipulations on doubles. This may or may not work. It is likely that the "&" by itself will force x to memory. But event if a #define is used to eliminate that, al least on may compilers the MOV X,I or equivalent will not work. Reluctantly, I would have to say that it might be necessary to put in a kludge and then edit the .s files, which is what I find myself forced to do in these situations. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (Internet, bitnet, UUCP)