Linus Torvalds writes: (Summary) For an expression that isn't constant, it's
a bit less obvious, and depends on knowing that "~x+1" is the same as
"-x" in 2's complement.
"-x" in 2's complement.
Of course, compilers *do* have that logic, but it's often deeper down than at parse-tree time.
than at parse-tree time.
Doing some simple testing on godbolt, I see that gcc-4.1 actually accepts this program:
accepts this program:
unsigned long x;
void *ptr= (void *)(x-x);
void *ptr= (void *)(x-x);
and clearly considers "(void *)(x-x)" to be NULL.
"-x" in 2's complement.
Of course, compilers *do* have that logic, but it's often deeper down than at parse-tree time.
than at parse-tree time.
Doing some simple testing on godbolt, I see that gcc-4.1 actually accepts this program:
accepts this program:
unsigned long x;
void *ptr= (void *)(x-x);
void *ptr= (void *)(x-x);
and clearly considers "(void *)(x-x)" to be NULL.