Re: [GD-General] The joy of type aliasing and C
Brought to you by:
vexxed72
From: Eero P. <epa...@ko...> - 2003-12-30 11:18:58
|
Alen Ladavac wrote: > Generally, trying to look at a float as if it's some kind of a black box that > stores real numbers, is kinda silly. You have to be aware of its internal > representation, or you can't work with it (without getting yourself into > various precision losses, etc). And once you are aware, you should be able to > access it. But I believe we all agree on that, and it's the standard that has > a wrong approach here. > I think that the standard has the aliasing rules, not because the comittee wanted to deny float->integer-bit-pattern conversions but because the comittee wanted the compiler produce better code in some other common situations. For example for some floating point vector library it is useful for the compiler to be sure that none of the limit/index integer values change, when the floating point results are written out. I think the aliasing rules make it easier to compete with fortran compilers here. The problem with int x=*(int *)&f; is sort of side effect here. I don't really know for sure why there must be a problem, because the aliasing of the values is sort of obvious, and could be deduced separately. Maybe the comittee just wanted to keep the definitions simple? Eero |