discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programming it's a play


From: Pascal J . Bourguignon
Subject: Re: Programming it's a play
Date: Sun, 21 Sep 2003 16:46:02 +0200

Dennis Leeuw writes:
> Pascal J.Bourguignon wrote:
> > you cannot say if doBar is an instance method or a class method, (it's
> > none, it  is a message!),  or if  foo refers a  class or an  object (a
> > class IS an object so it does not matter).
> 
> 
> Okay let's say I forget about the Apple documentation. And thus we say a 
> Class IS an object. And to prevent the chicken and egg problam some 
> looney invented the meta-class to overcome this.

Right.


> Then how about the Class object? Should we forget that one too?

Look at the headers:

typedef struct objc_class *MetaClass;
typedef struct objc_class *Class;

So, you see  that the type Class and the type  MetaClass are the same:
the only value of type MetaClass you'll find in an Objective-C program
is a Class!  

The difference is that with:

    Class aClass;
    Class theMetaClass;

you have:       aClass->class_pointer == theMetaClass
and:      theMetaClass->class_pointer == theMetaClass

That's where the chicken is the same as the egg: the looping metaclass.



Now, further look at:

struct objc_class {     
  MetaClass           class_pointer;          /* Pointer to the class's
  //...
};

typedef struct objc_object {
  struct objc_class*  class_pointer;
} *id;

You see  that both  an objc_class  begins with all  the fields  of the
objc_object structure.  That's how the  fact that a class is an object
is implemented.




You could try to read the whole C struct objc_class { }; and translate
it  to a @interface  declaration, to  see that  Class could  have been
declared  in   Objective-C  instead  of   C.   It's  done  in   C  for
bootstrapping  and  implementation   reasons  (the  runtime  functions
written in C need access  to this structure, and since these functions
are used  to implement Objective-C, they cannot  depend on Objective-C
stuff: you need them wholy defined in  C to be able to compile and run
an Objective-C program (another chicken and egg ;-).

> Although I think I will keep using a simplified metaphore within the 
> Guide. But getting the whole concept clear will make it possible for me 
> to comment in a later chapter on the example.

I'll read it ASAP.


-- 
__Pascal_Bourguignon__
http://www.informatimago.com/
Do not adjust your mind, there is a fault in reality.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]