Alex Rivera | Logout

In Cocoa, how is the id type defined?

Asked 2010-01-02T05:36:24.997
12

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.

Edit
Report

3 Answers

7

in objc.h

typedef struct objc_class *Class;
typedef struct objc_object {
    Class isa;
} *id;

To find out on your own, in XCode, right click id -- or any other type -- and select Jump to definition. It's interesting to note the similarities to other C/C++ based object systems; an object pointer -- an id -- points to a struct that starts with a point to shared class information. I many C++ implementations, that would be the virtual function table, as it would be with Microsoft's COM. In Cocoa, the particulars of objc_class aren't revealed to us in the header file.

answered 2010-01-02T05:44:57.923
2

The id type is generally declared like:

typedef struct objc_object *id;

This is critical for Objective-C++ where the type is part of a mangled function name.

You can take a look in /usr/include/objc/objc.h

answered 2010-01-02T05:46:37.177
0

You can refer the doc here : http://opensource.apple.com/source/objc4/objc4-437/runtime/objc.h Hope this will do a favor for you

answered 2012-02-16T06:40:17.347

Your Answer