• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: test if a pointer is pointing to a valid object or not?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >test if a pointer is pointing to a valid object or not? (From: Ben Dougall <email@hidden>)

  • Prev by Date: Cross Compiling 10.2 from 10.3 using a Makefile ???
  • Next by Date: Re: How to get Mac OS X System preference window from cocoa application
  • Previous by thread: test if a pointer is pointing to a valid object or not?
  • Next by thread: Re: test if a pointer is pointing to a valid object or not?
  • Index(es):
    • Date
    • Thread