This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Null pointer check elimination


"Michael N. Moran" <mike@mnmoran.org> writes:

| 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();

If no memory is available, the new-expression throws an exception so
the dereference never occurs.  Check out C++ manuals.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]