Re: test if a pointer is pointing to a valid object or not?
Re: test if a pointer is pointing to a valid object or not?
- Subject: Re: test if a pointer is pointing to a valid object or not?
- From: "Alastair J.Houghton" <email@hidden>
- Date: Tue, 28 Oct 2003 16:28:42 +0000
On Tuesday, October 28, 2003, at 04:05 pm, Ben Dougall wrote:
is there anyway to test if a pointer, that isn't NULL, is pointing to
a valid object or not? when you have a valid pointer to an object,
that pointer points to the isa of that instance. that isa points to
the class that it's an instance of. so i tried:
if( [object isKindOfClass:[NSObject class]] )
but that crashed when it wasn't a valid object. is there anyway to
safely test for a valid object?
Not with non-debug code. It isn't possible because you don't know what
is in the memory previously occupied by the object... it might very
well be a valid object, in which case you're going to send a message to
some other object in your application. Or it might look
(superficially) like a valid object, but actually be something else
entirely, in which case you'll probably crash when you try to call a
method.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.