Alexandre Oliva wrote: > > However, is there some way to get the desired semantics? > > If you insert an `asm ("" : "+X" (r2));' statement after the > assignment to r2, such that the compiler will no longer have any idea > that r2 is NULL, and won't optimize away the dereference. Ah, using asm() is an interesting idea and probably the most efficient way to do it.. however, your particular suggestion doesn't seem to work (the program still doesn't segfault).. $ cat > xx.c #include <stdlib.h> int main(int ac, char **av) { int *r1; int *r2; r1 = ∾ *r1 = 0; r2 = (void *)0; asm ("" : "+X" (r2)); if (*r1 != *r2) return 1; return 1; } ^D $ gcc -o xx -Wall -O2 xx.c $ ./xx $ It appears gcc is completely ignoring the possibility of "side effects" when it optimizes away the comparison. -Archie __________________________________________________________________________ Archie Cobbs * CTO, Awarix * http://www.awarix.com