diagnostic request

phr-2002@nightsong.com phr-2002@nightsong.com
Wed Feb 6 05:25:00 GMT 2002


The code

    int a[3] = {1, 2, 3};
    test() { a[a[0]]=1; }

looks like it sets a[1] to 1.  However, according to some intricate
reading of the ANSI C standard, its behavior is apparently undefined--
there's no sequence point after the computation of a[0].  Apparently
this is intended to allow vectorizing compilers to optimize array
assignments by assuming the arrays aren't "self-modifying".  I don't
understand the subtleties and may have gotten the example slightly
wrong, but there's a big thread about it in comp.std.c right now,
that's spilled over into sci.crypt.

I think GCC should compile the above code in whatever way it wants,
but it should print a diagnostic warning of a possible bug.



More information about the Gcc-bugs mailing list