And thus spake Seebs <usenet-nospam@seebs.net>
14 Feb 2010 07:03:57 GMT:
dereference a null pointer. (For instance, loops which check
whether a pointer is null may have the test removed because, if it
were null, it would have invoked undefined behavior to dereference
it...)
Sorry to interrupt, but since when is checking a pointer value
for 0 the same as deferencing it? Checking a pointer treats the
pointer itself as a value, and comparison against 0 is one of
the few things that are _guaranteed_ to work with a pointer
value. So if GCC really would remove a check of the form
if(!pointer)
do_something(*pointer);
or even
if(pointer == 0)
throw NullPointerException;
then GCC would be very much in violation of the standard. And
produce absolutely useless code, as well. What's the point of
having pointers in a language if you wouldn't even be able to
perform basic operations on them?
otherwise. For example: