Null pointer check elimination

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


Gabriel Dos Reis wrote:
> "Michael N. Moran" <mike@mnmoran.org> writes:
> 
> | Gabriel Dos Reis wrote:
> | > "Michael N. Moran" <mike@mnmoran.org> writes:
> | > | 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.
> | 
> | As a systems programmer (embedded), I frequently use "-fno-exceptions".
> | What behavior can I expect under these circumstances?
> 
> You have to manually check the return value of new.  There is no
> substitute for that.  At least, if you don't want to invoke that kind
> of undefined behaviour.

Fine. I must relent and remain surprised.
Going back to the root of this discussion, however:

| Joe Buck wrote:
| > 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.

I would simply expect the underlying memory allocator to be
invoked regardless of whether or not a pointer was null, but
honestly, in my line of work I rarely use the delete operator.


-- 
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