Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Cocoa, how is the id type defined?

Tags:

cocoa

This question is out of pure curiosity. How does Cocoa define the id type? Is it just a typedef for a void *? Also, if you know which header file it is defined in, I would be interested in taking a look.

like image 721
calvinlough Avatar asked Jan 02 '10 05:01

calvinlough


1 Answers

It is delcared in /usr/include/objc/objc.h (on Leopard) as follows:

typedef struct objc_object {
    Class isa;
} *id;

Which means it is not void * at all, but rather a pointer to a struct that contains a single member, pointing at the class definition. Interesting indeed.

I remember when I was just getting into C and learning that Objective-C was initially implemented as just a preprocessor layer on top of C. It isn't quite like that anymore.

The best reading on the topic I've found:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html

like image 195
Mike Avatar answered Oct 06 '22 17:10

Mike