• 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: New Cocoa Programmer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New Cocoa Programmer


  • Subject: Re: New Cocoa Programmer
  • From: Louis Demers <email@hidden>
  • Date: Mon, 12 Nov 2001 18:55:06 -0500

At 9:31 PM -0200 11/12/01, Rainer Brockerhoff wrote:
>From: Ondra Cada <email@hidden>
Date: Mon, 12 Nov 2001 18:23:11 +0100
If it is *not* the case, might you perhaps know why the following code is
uncompilable?

... switch (x) { case @selector(xyz): ... }

That should be (from the compiler's prespective) a pretty equivalent
situation as using class names there, or do I understand it improperly?

I would hazard a guess here; for the same reason that
char* string;
switch (string) {
case "abc":
...
case "xyz":
...
}
won't work. Aren't selectors and such ultimately implemented as (possibly mangled) strings?

unless OBJ C has seriously extended std. C, your switch statement can only use ints. This is basic C functionality. As written, it will take the string pointer and compare it with the pointer to "abc", "xyz" .... That would meaningless since having another string "abc" would be equivalent but using another memory location, it would be judged different. You may be confused with other C snippets like

int bozo;
switch (bozo) {
case 'abc':
...
case 'xyz':
...
}

where 'abc' are integers (up to 32 bits)
which equals ((97 * 256) + 98) * 256 + 99

You'll have to explicitly call string comparaison functions and parse the possibilities yourself, something like

if( 0 == strcmp (string, "abc") {
// do some brilliant coding here
} else if( 0 == strcmp (string, "...") {
// do some brilliant coding here
} else if( 0 == strcmp (string, "xyz") {
// do some brilliant coding here
} else if( 0 == strcmp (string, "xyz") {
}

--

Louis Demers ing.
email@hidden
email@hidden


  • Follow-Ups:
    • Re: New Cocoa Programmer
      • From: Ondra Cada <email@hidden>
    • Re: New Cocoa Programmer
      • From: Rainer Brockerhoff <email@hidden>
References: 
 >Re: New Cocoa Programmer (From: Rainer Brockerhoff <email@hidden>)

  • Prev by Date: Re: New Cocoa Programmer
  • Next by Date: Re: New Cocoa Programmer
  • Previous by thread: Re: New Cocoa Programmer
  • Next by thread: Re: New Cocoa Programmer
  • Index(es):
    • Date
    • Thread