Null pointer check elimination
Michael N. Moran
mike@mnmoran.org
Mon Nov 14 21:09:00 GMT 2005
Joe Buck wrote:
> On Mon, Nov 14, 2005 at 01:43:38PM -0500, Michael N. Moran wrote:
>>>Excuse me. IANALL nor am I a compiler expert but ...
>>what kind of optimization might be done with the information
>>that a reference *should* never be null? Especially within
>>the server code (the implementation of "int f(int& a)" in this case.)
>>> There are several examples. One is converting from a derived class
> to a base class when there is multiple inheritance. An offset must
> be subtracted, unless it is a null pointer.
>> Another is the "delete" operator. It must first check that the
> argument is null; it only calls the underlying memory allocator if it is
> not.
It's also surprising to me that the delete operator can
be used on a reference when the new operator returns a pointer
and the only way to get that (possibly null) pointer to be
used as a reference is to dereference it and then apply
delete on the pointer formed by the address-of operator on
the resulting reference....
void buzz(Abc& b)
{
delete &b;
}
void baz()
{
Abc& a = * new Abc();
buzz(a);
}
--
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