1

Possible Duplicate:
objective c difference between id and void *

While reading through NSZone.h in the Foundation framework I ran across a comment mentioning something being "more like a c style pointer than an id style object". I realized I don't understand the difference.

What is the difference between a c style pointer and an id style object?

2
  • 1
    At the 10,000 foot level an id is very much similar to a void* pointer. The distinction is that id is typed, but the type is "Objective-C object", a very large and "mushy" category. Commented Jan 31, 2012 at 21:30
  • 1
    Sorry, I read the article wrong. :( Incorrect answer deleted. Thanks for pointing that out, guys. Article here for reference: unixjunkie.blogspot.com/2008/03/id-vs-nsobject-vs-id.html Commented Jan 31, 2012 at 21:32

2 Answers 2

1

A C pointer can point at anything - objects, structures, raw bytes, strings, ...

A 'id' pointer is pointing at an instance of an Objective-C object. 'id' is untyped, so it could be pointing at an instance of any class. Something like NSObject* is typed; you know what kind of object it is pointing at.

Sign up to request clarification or add additional context in comments.

Comments

1

The header appears to be talking specifically about how things are treated by the Objective-C garbage collector. Generic pointers obtained from malloc() are not managed by the collector, while objects are. That comment is on NSMakeCollectable(), a function that enables GC on CoreFoundation-style objects.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.