Re:The Dangers of Super Smart Compilers
by Kristine1975 on Sunday December 20, 2015 @09:34AM
(#10767113)
Some systems allow you to dereference NULL
For example inside the Linux kernel. GCC has the special switch "-fno-delete-null-pointer-checks" that turns off the assumption that a dereferenced pointer is never null: https://homes.cs.washington.edu/~akcheung/papers/apsys12.htm...
Re:The Dangers of Super Smart Compilers
by gizmo686 on Sunday December 20, 2015 @12:44PM
(#10767647)
My understanding of the C standard is that is explicitly does not allow you to dereference NULL, even if you really want to know what is at memory address 0. Of course this behaviour is only undefined, so an implementation if free to let you do it if it wants to.
Re:The Dangers of Super Smart Compilers
by Kristine1975 on Sunday December 20, 2015 @01:10PM
(#10767723)
Minor nitpick: A NULL pointer need not point to memory address 0 (e.g. it could point to the highest possible address, or have a special "this is a NULL pointer" bit set). The C11 Standard does a little dance with "null pointer" and "null pointer constant" there, c.f. chapter 6.3.2.3:
An integer constant expression with the value 0 [...] is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
The real question is, how does anyone compile without "-Wall -Werror" in 2015? Ignoring your compiler when it tells you your code is wrong is negligence.