[Uml-devel] dynamic_cast usage

Luis De la Parra Blum lparrab at gmx.net
Thu Dec 19 10:58:05 UTC 2002

> this is getting a bit OT, but its fun :)
> i'm gonna go with john on this one. unitialized and NULL aren't the same
> thing. 

of course not, they are not the same.  if you delete a pointer that is 
uninitialized and it happens to contain garbage, the of course you are going 
to run into trouble.
but the whole discussion began because of code like
	delete foo;

if your pointer is uninitialized then the "if"-check is not going to help you 
in any way.(ok, if you are using linux and have good luck it's going to be 
zero, but you can't depend on that, so assume it contains garbage), 

The "If" is to *try* to make sure the pointer is pointing to something. As I 
said, if it contains zero, then you don't need the "if", because the language 
assures you nothing will happen... on the other hand, if it doesnt contain a 
value of zero (for example, if it contains garbage), then the "if" will not 
do anything, so a code like the above, and a code like

delete foo;

are *exactly* the same in that they do the same thing, but the second might be 
a little faster.

to close up, the correct thing to do would be to use smart pointers (for 
example boost), or make sure after each delete we set the pointer to zero.
otherwise you have deleted the object, but the pointer still contains a value 


More information about the umbrello-devel mailing list