Re: XCode const warnings
Re: XCode const warnings
- Subject: Re: XCode const warnings
- From: Peter Wollschlaeger <email@hidden>
- Date: Fri, 13 Feb 2004 18:50:48 +0100
to show all variations
// pointer to a constant string
const NSString * ptr_1;
ptr_1 = @"foo_1";
// constant pointer to string
NSString * const ptr_2;
ptr_2 = @"foo_2"; //gives a warning, but ptr_2 can be used
// constant pointer to constant string
NSString * const * ptr_3;
ptr_3 = @"foo_3"; //gives a warning, but ptr_3 can be used
Cheers
Peter
Am 13.02.2004 um 17:48 schrieb Clark Cox:
>
On 2004/02/13, at 10:57, Darrin Cardani wrote:
>
>
> I have a project I've been building with Project Builder. I recently
>
> moved the project to XCode and am now getting some warnings I wasn't
>
> getting with PB. For example, I'm calling NSMutableString's
>
> replaceOccurrencesOfString:withString:options:range method. The
>
> "withString" parameter I'm passing is declared as:
>
>
>
> const NSString* myString = @"blah";
>
>
>
> So I'm getting the warning:
>
>
>
> invalid conversion from `const NSString*' to `NSString*'
>
>
>
> I guess the compiler's right, but since it requires an NSString
>
> instead of an NSMutableString, it shouldn't make any difference,
>
> should it? I can cast away the const-ness, but I just want to make
>
> sure that's not going to cause any problems. Is it? I have a couple
>
> dozen of these warnings. Should I be avoiding using NSStrings as
>
> constants, and instead just make them regular globals?
>
>
>
> I also get a similar problem when putting these constant strings into
>
> NSDictionaries. I get:
>
>
>
> invalid conversion from `const NSString*' to `obc_object*'.
>
>
>
> I just want to make sure whatever I do is safe. Any suggestions would
>
> be appreciated.
>
>
>
Use "NSString *const myString" instead of "const NSString *myString".
>
>
--
>
Clark S. Cox III
>
email@hidden
>
http://homepage.mac.com/clarkcox3/
>
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html
>
>
[demime 0.98b removed an attachment of type
>
application/pkcs7-signature which had a name of smime.p7s]
>
_______________________________________________
>
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.
_______________________________________________
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.