On Wed, 21 Dec 2005, Robert Dewar wrote: > Gabriel Dos Reis wrote: > > >with no more qualifications (this definition is slightly different in > >some nearby languages), it is slippery to found optimizations on > >"pointer overflows." > > > > > Well I think unfortunately the standard does allow such "optimizations", but > that does > not mean it is a good thing to take advantage of this.
Another example is char a[2]; void foo(void) { char *p = &a[1]; if (p + 0xffffffff > p) abort (); } where, on a 32bit arch, p + 0xffffffff will point to a[0] (does the std say so?), but we still optimize the test to if (1) abort (); because we say "pointer overflow" is undefined. Using p - 1 > p will work as expected. So the basic question remains - is pointer overflow defined? Richard.