Re: Help about the complexity of code
- From: zaimoni@xxxxxxxxxxx
- Date: Mon, 8 Jun 2009 12:11:40 -0700 (PDT)
On Jun 8, 8:44 am, Jeff Lait <torespondisfut...@xxxxxxxxxxx> wrote:
On Jun 8, 1:42 am, Keith H Duggar <dug...@xxxxxxxxxxxx> wrote:
On Jun 7, 10:46 pm, zaim...@xxxxxxxxxxx wrote:
In short, in this case C++ is providing flexibility to implementors
to use more advanced error trapping techniques than just setting it
NULL should they desire. Whether implementors take advantage of the
freedom or not is a matter outside of the C++ language itself.
If it isn't part of the standard, I can't rely on it. The whole
advantage of having pointers auto-null is so one can write stuff like
delete myData;
without always having to reflexively write:
myData = 0;
in fear of some later code calling delete myData; or relying on NULL
to signify an unassigned pointer.
If my platform did auto-NULL deletes, it would be folly to rely on it,
since
delete myData;
delete myData;
would work fine on my platform, but crash with a double-free on
platform X that decided to take a different implementation.
I've had enough pain in my life from Irix's MIPS processors happily
letting people read/write from NULL pointers.
In this particular case, any half-way competent compiler can figure
out when that proposed ptr = NULL; assignment is no-effect code (when
it is clearly traceable that a valid pointer is written to that
variable before it is read from again), so you still don't pay for
what you don't use:
In some cases it would be easy. In others it would be impossible.
But, in any well written C++ program, someone is *already* NULLing the
pointer by hand after every delete. The only time they don't auto-
Null is when they've done manual code-flow analysis to verify no one
will read from the pointer before the next write... Analysis, which I
suspect, would be better done by said compiler.
Precisely.
And this
change certainly doesn't break any already-conforming programs.
It could break implementations that provide trapping; see above.
Programs that actually *trigger* such trapping are already non-
conforming (they invoke undefined behavior).
I'm quite curious as to what this would consist of. Can you please
give some links to examples? I'd guess they switch the pointer to a
different known value that still triggers a crash on access?
While recent versions of Windows do provide such trapping much of the
time, the result of assigning NULL to a pointer is rigged so that it
does trap.
.
- Follow-Ups:
- Re: Help about the complexity of code
- From: Gelatinous Mutant Coconut
- Re: Help about the complexity of code
- References:
- Help about the complexity of code
- From: n . haghn
- Re: Help about the complexity of code
- From: Nathan Stoddard
- Re: Help about the complexity of code
- From: Gerry Quinn
- Re: Help about the complexity of code
- From: zaimoni
- Re: Help about the complexity of code
- From: Nathan Stoddard
- Re: Help about the complexity of code
- From: Jeff Lait
- Re: Help about the complexity of code
- From: zaimoni
- Re: Help about the complexity of code
- From: Keith H Duggar
- Re: Help about the complexity of code
- From: Jeff Lait
- Help about the complexity of code
- Prev by Date: Re: Help about the complexity of code
- Next by Date: Re: Help about the complexity of code
- Previous by thread: Re: Help about the complexity of code
- Next by thread: Re: Help about the complexity of code
- Index(es):
Relevant Pages
|