[Uml-devel] dynamic_cast usage

Andrew Sutton ansutton at kent.edu
Wed Dec 18 21:00:02 UTC 2002


On Wednesday 18 December 2002 1:16 pm, Luis De la Parra Blum wrote:
> On Wednesday 18 December 2002 22:53, Jonathan Riddell wrote:
> > > Another thing I just noticed: deleting a 0L-pointer is perfectly valid,
> > > i.e. there is no need check for non-0L before deleting something, like
> > > if ( foo )
> > > 	delete foo;
> >
> > Of course you have to make sure that foo really is null first and not
> > completely uninitialised!
>
> nop.
> Carsten is right there. If you delete a pointer whose value is 0L, nothing
> happens (this is assured by the language)
>
> the only problem is if you delete some object and NOT set the pointer to
> null or if you have two pointer to the objects, but in those cases doing a
> if(foo) won't help either.

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, in some situations, pointers are initialized to NULL - 
particularly pointer values in the data segment of a process - but that 
really depends on the kernel. i think linux zeroes out the memory used for 
global data as a security precaution (i think windows does too). of course, 
if the ptr is on the stack, it depends on the compiler. IIRC M$ compiler in 
debug mode will initialize ptrs to 0xFCFCFCFC. there's a an ASSERT_VALID() 
macro or something that tests for that. if the ptr is allocated on the heap, 
its most likely arbitrary data - then you can't tell. unless you set the 
value to something less arbitrary (like 0xFCFCFCFC). then you can test for 
validity.

see. fun :)

andy




More information about the umbrello-devel mailing list