This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bug: pointer subtraction not commutative in egcs-1.0


> [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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]