Re: NSString equivalent of CFSTR macro?
Re: NSString equivalent of CFSTR macro?
- Subject: Re: NSString equivalent of CFSTR macro?
- From: Greg Parker <email@hidden>
- Date: Mon, 04 Dec 2017 14:55:45 -0800
> On Dec 4, 2017, at 2:51 PM, Ben Kennedy <email@hidden> wrote:
>
>> On Dec 4, 2017, at 2:47 PM, Rick Mann <email@hidden> wrote:
>>
>> #define NSSTR(s) (@ ## s) <-- magic; this
>> doesn't work
>> #define kSomeCStringConstant "foo"
>> ...
>> NSSTR(kSomeCStringConstant)
>
> You're close. The preprocessor is removing the quotation marks, breaking the
> syntax. You don't need to token paste; simply remove the '##' from the
> NSSTR() def.
>
> #define NSSTR(s) (@ s)
You can also skip the middleman and use `@kSomeCStringConstant`. After the
preprocessor runs it will be `@"foo"` which the ObjC compiler is perfectly
happy with.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden