Null pointer check elimination

Michael N. Moran mike@mnmoran.org
Mon Nov 14 22:28:00 GMT 2005


Gabriel Dos Reis wrote:
> "Michael N. Moran" <mike@mnmoran.org> writes:
> | From info gcc:
> | 
> | `-fdelete-null-pointer-checks'
> | Use global dataflow analysis to identify and eliminate useless
> | checks for null pointers. The compiler assumes that dereferencing
> | a null pointer would have halted the program. If a pointer is
> | checked after it has already been dereferenced, it cannot be null.
> | 
> | The second sentence makes me question the difference between an
> | actual dereferencing operation and the use of a dereferencing
> | operator used to convert a pointer to a C++ reference. Clearly
> | (to me anyway ;-) the conversion case does not actually cause
> | an access to the object.
>> It is not a conversion. It is a dereference operation that is defined
> only for non-null operand. No ifs, no buts.

I'm in over my head, but ... (oops there's a but ;-) here goes:
void bar(int& a);
void foo(int* a)
{
 // dereference: conversion to reference
 // Since there is not necessarily any object access,
 // thus no assured SEGFAULT.
 bar(*a);
 // dereference: access to object
 // If a is null, then SEGFAULT
 *a	= 0;
}
Sorry to drag this out. I'm sure its just one of those
"that's the way the language is defined Moran get over it"
issues, but (no ifs) ...
-- 
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA, USA 30144 http://mnmoran.org
"So often times it happens, that we live our lives in chains
 and we never even know we have the key."
The Eagles, "Already Gone"
The Beatles were wrong: 1 & 1 & 1 is 1


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /