Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!skipper!elxsi!maine From: maine@elxsi.dfrf.nasa.gov (Richard Maine) Newsgroups: comp.lang.fortran Subject: Re: Type punning in C Message-ID: Date: 12 Oct 89 16:17:34 GMT References: <475@idacrd.UUCP> <1989Oct10.185851.6490@agate.berkeley.edu> <1989Oct11.091619.18336@gdt.bath.ac.uk> <1654@l.cc.purdue.edu> Sender: news@skipper.dfrf.nasa.gov Followup-To: comp.lang.fortran Organization: NASA Dryden, Edwards, Cal. Lines: 38 In-reply-to: cik@l.cc.purdue.edu's message of 12 Oct 89 12:21:18 GMT In article <1654@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: > ... [discussion about type punning and equivalence] > It should not even bother an optimizer. The optimizer takes the operations > given by the programmer, in some cases applies transformations known to > provide the same result, and optimizes the order. Why should an integer > and a floating point number in the same location bother it, unless that > location is a register and the (expletives deleted) hardware has different > integer and floating registers? But even that should not befuddle the > optimizer. Well, you partially answered your own question. The optimizers often play register allocation games and this can certainly interfere with that. Do recall that the Fortran standard is intended to apply to many varieties of hardware, including some that deserve the deleted expletives. Actually, even perfectly standard equivalences involving no type punning can and often do mess up optimizers. The optimizer just "forgets" to account for the possibility of variable references or definitions through the equivalence. This is far from a trivial issue. Ok, it may not be a "good" reason, and you can bitch about the sloppy compiler all you want (I do), but I guarantee its a real reason. I have seen many instances of such bugs in many compilers (usually when helping other people debug their programs). I try to avoid equivalence and its ilk as much as possible, both for the usual clarity/style reasons and to lessen my exposure to this class of compiler bugs. Of course, "as much as possible" doesn't mean always. I'm guilty. I've done it and will undoubtedly do it again. BUt I do regret it every time. -- Richard Maine maine@elxsi.dfrf.nasa.gov [130.134.1.1]