[comp.lang.c] aliasing

chad@lakesys.UUCP (D. Chadwick Gibbons) (08/14/89)

        I was reading through some article and noticed a mention of aliasing
and optimization problems.  Having no idea what aliasing was, I tried finding
it in the pseudo-programmer's manual; not being satisfied with the answer (as
I expected) I seek the guru's answers.

        Aliasing: referring to more than one memory location by two different
names.  Some compilers can preform special optimization if you ignore aliasing
checking.  "Safe" aliasing would consist of the following:

        func()
        {
            int x, *p = &x;

            /* ...only *p is used in the remainder of the function... */
        }

Here, aliasing optimization would be preformed without hazardous results. An
example of unsafe optimization would be:

        int x;
        func(p)
        int *p;
        {
            /* expressions involving *p and x */
        }

Which, if nothing else, would seem asinine to do.  Is this much of my
understanding correct?  I think it is, but I'm foggy on it, to say the least.

        And what about the "noalias" keyword that may or may not (?) be
adopted by XJ311?  Of what use would that be?
-- 
D. Chadwick Gibbons, chad@lakesys.lakesys.com, ...!uunet!marque!lakesys!chad