Julián Albo said:
I don't see why the compiler needs to do that if you are only doing
something with the value of the pointer but not dereferecing it.
In C++, you don't pay for what you don't use. Generally.
Consider a slow opcode FOO that carefully copied out the segment and offset
from such a hypothetical pointer. Suppose this CPU also had a fast opcode
BAR that exploited the CPU's microcode to copy out the pointer's value, but
this BAR threw an automatic hardware exception if the segment and offset
are not valid.
(Such hardware exceptions are often how overcommitted virtual memory works.)
A C++ compiler cannot guess which pointers are valid and which should not be
used as rvalues. This code causes undefined behavior:
int * p = new int;
delete p;
assert(NULL != p); // <-- undefined behavior
Our hypothetical compiler must use the BAR opcode in that assertion, because
all the times we use pointers for defined behavior must be fast.
(BTW the assertion itself is well-formed, and won't cause the first
undefined behavior.)