4 ms·
> but gcc will definitely elide an if check if it detects pointer dereference inside the if block As others have stated, this is almost certainly incorrect. >
by aw1621107 3y ago
> but gcc will definitely elide an if check if it detects pointer dereference inside the if block
As others have stated, this is almost certainly incorrect.
> The reasoning was that if a pointer is being dereferenced, it must be non null.
The key here is "if a pointer is being dereferenced". In that case the pointer is only dereferenced if the condition evaluates to true and does nothing otherwise. The optimizer would be incorrect to turn that into an unconditional dereference.