• 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: Creation of constants
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creation of constants


  • Subject: Re: Creation of constants
  • From: j o a r <email@hidden>
  • Date: Fri, 31 Oct 2003 12:44:25 +0100

On 2003-10-31, at 11.45, Alastair J.Houghton wrote:

Well, one reason is that #define'd constants don't end-up as symbols in the debugger on most systems.

OK, makes sense.

For string constants, you can declare an external global variable e.g.

extern const char *MY_C_STRING;
extern NSString *MY_NS_STRING;

Why did you use the const type qualifier for the (char *) and not the (NSString *)?

When I do this:

const NSString *kMyKey = @"MyKey";

...instead of this:

const id kMyKey = @"MyKey";

...I get this warning:

MyClass.m:666: warning: passing arg 1 of `isEqualToString:' discards qualifiers from pointer target type

...for this piece of code:

if ([key isEqualToString: kMyKey])

Why is that, and how would you fix it - by using id, or by removing const? I notice that if I omit the const type qualifier, I no longer get the warning - but then I also loose the benefits of using the type qualifier.

j o a r
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Creation of constants
      • From: "Alastair J.Houghton" <email@hidden>
References: 
 >Re: Creation of constants (From: "Alastair J.Houghton" <email@hidden>)

  • Prev by Date: NSComboBoxCell ugliness
  • Next by Date: Re: Creation of constants
  • Previous by thread: Re: Creation of constants
  • Next by thread: Re: Creation of constants
  • Index(es):
    • Date
    • Thread