This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C aliasing rules question.


On Sunday, May 18, 2003, at 02:46 PM, Falk Hueffner wrote:
static inline int f_trunc(float f)
{
        f -= 0.5f;
        f += (3<<22);
        return *((int*)(char*)&f) - 0x4b400000;

I don't think so. Even if it happens to work right now, I don't think it should be supported in the long run. What's so bad about using a union?

Every so often I just have to try again.


a) There's much existing code that looks like the above;

b) A union is no more standard than the above;

c) Most people think the above is legal, so we'll keep getting
bug reports until it works in the obvious fashion;

d) This sequence occurs in SPEC (in code from gcc itself!).  Inability
to compile SPEC has immediately removed gcc from consideration as
the house compiler in two situations I know of, and probably a lot
more (nobody cares that it's nonstandard);

e) The examples in the C89 Rationale defending the type-based aliasing
rules all involve multiple functions, situations where the compiler
cannot tell whether things alias or not (lacking IPA, which is obviously
not something you want to require).  That's not the case here.  It is
just not that hard to tell that two references to the same, known
address interfere, without losing optimization opportunities.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]