FROM : glenn andreas
DATE : Wed Feb 06 21:23:26 2008
On Feb 6, 2008, at 11:05 AM, Jean-Daniel Dupas wrote:
>>>
>>
>> Structures don't have "magic invisible members":
>>
>> @interface Foo {
>> }
>> @end
>>
>> Foo *aFoo;
>> NSLog(@"Foo is a %@", aFoo->isa);
>>
>> Notice how there is an "isa" member that is automatically put
>> there, not unlike the way that a C++ object might have a vtable (or
>> other internal plumbing for multiple inheritance).
>>
>
>
> Wrong. This will not work. Foo will not have a magic isa ivar, an is
> not a valid objc class.
>
> You have to either:
> 1) inherit from a valid root class (NSObject).
> 2) add a "Class isa" ivar to your declaration.
>
> See the NSObject declaration:
>
> @interface NSObject <NSObject> {
> Class isa;
> }
> ...
> @end
Mea culpa - someday I'll learn to not post until the _second_ cup of
coffee....
Perhaps a more accurate statement is that it has an "explicit magic
member" - it must have an isa pointer as the very first field
(contrary to the caffeine deprived ruminations, the compiler doesn't
put it there automatically).
Regardless, all objects must start with that isa pointer - the runtime
requires it. Objects _are_ special, and pretending that this is just
another arbitrary struct is incorrect:
1) They can't live on the stack
2) They have a special isa pointer
3) They have implicit requirements to be allocated/copied/released
using special routines (NSAllocateObject, NSCopyObject,
NSDeallocateObject) - i.e., it's unclear if you attempted to malloc or
new a structure of the same type and manually filled in the isa
pointer would necessarily work on current or future Objective-C
runtimes (it would almost certainly fail under 64 bit Objective 2.0)
Glenn Andreas <email_removed>
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next
generation of fractal art
DATE : Wed Feb 06 21:23:26 2008
On Feb 6, 2008, at 11:05 AM, Jean-Daniel Dupas wrote:
>>>
>>
>> Structures don't have "magic invisible members":
>>
>> @interface Foo {
>> }
>> @end
>>
>> Foo *aFoo;
>> NSLog(@"Foo is a %@", aFoo->isa);
>>
>> Notice how there is an "isa" member that is automatically put
>> there, not unlike the way that a C++ object might have a vtable (or
>> other internal plumbing for multiple inheritance).
>>
>
>
> Wrong. This will not work. Foo will not have a magic isa ivar, an is
> not a valid objc class.
>
> You have to either:
> 1) inherit from a valid root class (NSObject).
> 2) add a "Class isa" ivar to your declaration.
>
> See the NSObject declaration:
>
> @interface NSObject <NSObject> {
> Class isa;
> }
> ...
> @end
Mea culpa - someday I'll learn to not post until the _second_ cup of
coffee....
Perhaps a more accurate statement is that it has an "explicit magic
member" - it must have an isa pointer as the very first field
(contrary to the caffeine deprived ruminations, the compiler doesn't
put it there automatically).
Regardless, all objects must start with that isa pointer - the runtime
requires it. Objects _are_ special, and pretending that this is just
another arbitrary struct is incorrect:
1) They can't live on the stack
2) They have a special isa pointer
3) They have implicit requirements to be allocated/copied/released
using special routines (NSAllocateObject, NSCopyObject,
NSDeallocateObject) - i.e., it's unclear if you attempted to malloc or
new a structure of the same type and manually filled in the isa
pointer would necessarily work on current or future Objective-C
runtimes (it would almost certainly fail under 64 bit Objective 2.0)
Glenn Andreas <email_removed>
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next
generation of fractal art






Cocoa mail archive

