In article <3P******************************@posted.comnet> ,
Alf P. Steinbach <al***@start.nowrote:
>* ma740988:
>Victor, Greg as always, thanka alot. One last item on this. There's
a common guideline - if you will - that suggests
if ( ptr_ )
delete ptr_ ;
I'm trying to understand why would I _ever_ do that?
The 'if' will always be redundant.
> Thus far the
only scenario I could concoct surrounds:
delete ptr_ ; // item 1
// in some other translation unit.. later I do
delete ptr_ ; // item 2
item 1: Ok there.
item 2: I suspect here I could solve a potential issues with an 'if
( ptr_ )'.
No, you could not.
Anyway that 'if' is performed by 'delete'.
>Trouble, is, if I opt to delete a pointer twice, then I'm a
mook, something is amiss in the code.
Oh well, it's a guideline though I might add I find it (literally)
drives me insane wnen I encounter it.
Good. Because that means you still have a working mind. :-)
As opposed to those writing the guideline.
Once upon a time, in a galaxy far far away, it was actually
unclear what delete of a null pointer did, same as free()ing
a null pointer -- different implementations did different things.
So the original intents of some of these rules makes sense.
On the on side of the coin, consistency in coding guidelines
makes sense, but of course sometimes logic defies itself.
Also, there are some who have determined that for their own
code that the if is faster in some critical code, although
I never quite totally bought that argument even if they
could show me their (no doubt correct) timing results.
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?