Jens M Andreasen said:
What you say is correct, but in context wrong.
No, that's entirely right in context. There's nothing in the Standard
that forbids that if statement to be compiled to something like
LD ADDR1, null
LD ADDR2, (p)
CMPADDR
JMPEQ afterif
Nor is there anything forbidding that an invalid pointer causes a
segfault at the processor level if it's loaded into an address register.
If p is valid but not null, this results in
LD ADDR1, null (ok, ADDR1 contains a null pointer)
LD ADDR2, (p) (ok, ADDR2 contains the contents of pointer p)
CMPADDR (ok, equal flag is set to zero)
JMPEQ afterif (ok, jump does not take place)
If p is a null pointer, it results in
LD ADDR1, null (ok, ADDR1 contains a null pointer)
LD ADDR2, (p) (ok, ADDR2 contains the contents of pointer p,
which is also a null pointer)
CMPADDR (ok, equal flag is set to one)
JMPEQ afterif (ok, jump does take place)
If, OTOH, the segment that p pointed to has just been deallocated, it
could result in
LD ADDR1, null (ok, ADDR1 contains a null pointer)
LD ADDR2, (p) (not ok. The processor detects an attempt to load a
pointer into ADDR2 which is not valid, and causes a trap. The OS
reacts to this by terminating your program with extreme prejudice.)
Richard