bug: pointer subtraction not commutative in egcs-1.0
Tobias Gloth
gloth@unknown.westfalen.de
Mon Dec 29 16:31:00 GMT 1997
> [snipped a quite long example]
Simply put, this is the problem:
-----------------------------------------
#include <assert.h>
#include <stdio.h>
int main () {
short *foo;
int *foo0 = (int*)(foo+0);
int *foo1 = (int*)(foo+1);
assert (foo0-foo1 == -(foo1-foo0));
}
-----------------------------------------
I don't know what the ANSI-standard tells us about this, but my feeling
is that the program is plainly broken, and the result of the subtraction
should be undefined.
SGI's C-compiler "fails" on this as well. SGI's C++-Compiler has no
problem, as well as Sun's and IBM's C and C++ Compiler.
Tobias
More information about the Gcc-bugs
mailing list