Re: Usage of +class
Re: Usage of +class
- Subject: Re: Usage of +class
- From: Ondra Cada <email@hidden>
- Date: Sat, 22 Apr 2006 19:04:09 +0200
Jonathon,
On Apr 22, 2006, at 5:42 PM, Jonathon Mah wrote:
A class identifier has two uses: a _type_, and a message receiver.
Right.
Contrast this to a variable, which has two uses: a _value_, and a
message receiver.
Not quite. A variable has (in this sense) just one use -- its value.
Which, among others, may be used as a message receiver.
Interestingly, you can change the use of a class name from a type
to a value:
That is just since it is an identifier, and not a keyword. ObjC
designers (unlike the Stroustrup guy) were smart enough to design
nearly *all* the extensions as identifiers (or at worst, like nil or
Nil, macros), thanks to which you can declare them in inner scopes
wherever you want to:
17 /tmp> >q.m
#import<Cocoa/Cocoa.h>
int main() {
#undef nil
#undef Nil
int id=1,nil=2,Nil=3,Class=4,SEL=5,IMP=6;
NSLog(@"%d %d %d %d %d %d",id,nil,Nil,Class,SEL,IMP);
return 0;
}
18 /tmp> cc -Wall q.m -framework Cocoa && ./a.out
2006-04-22 19:03:06.423 a.out[4133] 1 2 3 4 5 6
19 /tmp>
void *NSString = temp;
NSLog(@"Class address: %u", [NSString class]); // Valid (but
warning)
And in majority of cases a message sent to something you did not want
it to be sent to, which may case crash, or worse, no crash and
improper function.
I think I've beaten this to death now.
Well yes and no: since you added scoping, things like the difference
between enum/typedef/#define and so forth might be discussed. But
that would be stuff for some generic plain C list, not a Cocoa one.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden