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?

Community
  • 1
  • 1
SundayMonday
  • 19,147
  • 29
  • 100
  • 154
  • 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. – Hot Licks Jan 31 '12 at 21:30
  • 1
    Sorry, I read the article wrong. :( Incorrect answer deleted. Thanks for pointing that out, guys. Article here for reference: http://unixjunkie.blogspot.com/2008/03/id-vs-nsobject-vs-id.html – Almo Jan 31 '12 at 21:32

2 Answers2

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.

Graham Perks
  • 23,007
  • 8
  • 61
  • 83
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.

Chuck
  • 234,037
  • 30
  • 302
  • 389