Re:“Unexplainable” core dump (2011)
by 3836293648 on Wednesday January 04, 2023 @12:51AM
(#34242472)
You can check if the address is 0, but the value of the nullptr is implementation definied behaviour. You can have a system where the null pointer is 4.
And address 0 isn't too special on a machine level either. Embedded systems have valid data to read and write there.
Yeah based on https://joelaro.wordpress.com/2015/09/30/gcc-optimization-fd... the assumption is that if the pointer was previously dereferenced, it can be assumed to be non-null, and hence all subsequent null-checks can be elided.
Based on https://news.ycombinator.com/item?id=17360772, the case in which this actually makes a difference is an address offset like
The compiler knows the structure so it can just inline the offset, but the optimizer considers this as being non-null.