• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Usage of +class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Usage of +class (From: Jonathon Mah <email@hidden>)
 >Re: Usage of +class (From: j o a r <email@hidden>)
 >Re: Usage of +class (From: Jonathon Mah <email@hidden>)

  • Prev by Date: Re: debugger problem
  • Next by Date: Re: debugger problem
  • Previous by thread: Re: Usage of +class
  • Next by thread: Core Data Merged Models
  • Index(es):
    • Date
    • Thread