This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: bug: pointer subtraction not commutative in egcs-1.0
- To: raymond at magma-da dot com (Raymond Nijssen)
- Subject: Re: bug: pointer subtraction not commutative in egcs-1.0
- From: gloth at unknown dot westfalen dot de (Tobias Gloth)
- Date: Tue, 30 Dec 1997 02:16:59 +0100 (MET)
- Cc: egcs-bugs at cygnus dot com
> [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