Vee
Vee

Reputation: 1841

Accessing Xcode LLVM Processor Macros

In the "Apple LLVM 7.0 - Preprocessing" section under the "Build Settings" tab, I've defined a Preprocessor Macros as:

HUBNAME=myhub

In my code, I'm trying to refer to the value of HUBNAME as a string:

SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:HUBLISTENACCESS notificationHubPath:HUBNAME];

But Xcode thinks 'myhub' is the name of my variable:

Use of undeclared identifier 'myhub'

Can someone help me figure out how to access 'myhub' as a string?

Upvotes: 1

Views: 84

Answers (1)

Cai
Cai

Reputation: 3649

Something like TO_STR(arg)=#arg HUBNAME=TO_STR("myhub")? (or just TO_STR(myhub) w/o quote.)

NSLog(@"%s", HUBNAME); // SO36947532[13085:4401425] myhub

From GNU:

3.4 Stringification

Sometimes you may want to convert a macro argument into a string constant. Parameters are not replaced inside string constants, but you can use the # preprocessing operator instead. When a macro parameter is used with a leading #, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant. Unlike normal parameter replacement, the argument is not macro-expanded first. This is called stringification.

Xcode

Upvotes: 1

Related Questions