The problem is the code unconditionally dereferences the pointer, which would be UB if it was a null pointer. This means it is legal to optimize out any code paths that rely on this, even if they occur earlier in program order.
But if the assertion fails, the program is aborted before the pointer would have been dereferenced, making it not UB. This explanation is bogus.
> The problem is the code unconditionally dereferences the pointer, which would be UB if it was a null pointer.
Only when NDEBUG is defined, right?
> it is legal to optimize out any code paths that rely on this, even if they occur earlier in program order.
I don't think this is true. The compiler cannot remove or reorder instructions that have a visible effect.
The printf() can't be omitted.