Re: Is there such a thing as a global constant (string) in obj-c?
Re: Is there such a thing as a global constant (string) in obj-c?
- Subject: Re: Is there such a thing as a global constant (string) in obj-c?
- From: Glenn Andreas <email@hidden>
- Date: Wed, 21 Jul 2004 10:45:11 -0500
At 9:38 AM -0500 7/21/04, John Spicer wrote:
I've been trying to make one. I tried putting it in the main file as
this
NSString *myconst = @"thedatabit";
and that compiles OK. I then declare it as this in a file I want to use
it in:
extern const NSString *myconst;
which again compiles ok, BUT I get this warning when I try to use it in
a message [myObject selectMyString:myconst];
passing arg 1 of `selectMyString:' discards qualifiers from pointer
target type
It really means that you shouldn't send an Objective-c message to a
const pointer (ultimately this boils down to a call to
objc_msgSend(id self , SEL op, ...) and not objc_msg_send(const id
self,SEL op, ...) so you, in fact, ar passing a const Foo * to
something declared as Foo *, and thus the warning).
Just remove the const from "extern const NSString *myconst;" (since
the const doesn't do what you expect it to anyway).
If you look you'll see that all the NSSomeConstantString are declared
without the const as well.
--
Glenn Andreas email@hidden
mondo blobbo, Cythera, Theldrow, oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
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.