On Tue, 2009-01-27 at 00:11 -0800, James Dennett wrote: > On Mon, Jan 26, 2009 at 11:52 PM, <zol...@bendor.com.au> wrote: > > I was debugging a function and by inserting the debug statement crashed > > the system. Some investigation revealed that gcc 4.3.2 arm-eabi (compiled > > from sources) with -O2 under some circumstances assumes that if a pointer > > is dereferenced, it can not be NULL therefore explicite tests against > > NULL can be later eliminated. > > That's an optimization permitted by the language standard, but > possibly unhelpful on your particular target. It is a case of a more > general situation: the compiler can assume that code containing > "undefined behavior" (such as a null-pointer dereference) is not > executed, or equivalently that a condition that would lead to the > execution of UB is always false.
Just curious: is there a "portable" way to read from memory address zero in C code? "portable" here means likely to work on most compilers without exotic compile flags in 2009. Thanks in advance, Laurent