1

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?

Anton Korobeynikov
  • 9,074
  • 25
  • 28
Vee
  • 1,821
  • 3
  • 36
  • 60

1 Answers1

1

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

Cai
  • 3,609
  • 2
  • 19
  • 39
  • Thanks! Worked like a charm. The one thing to note is that I had use "@HUBNAME" when accessing the macro from my code. – Vee May 02 '16 at 14:35
  • Any chance you can address a related question:http://stackoverflow.com/questions/36988067/stringify-endpoint-for-xcode-llvm-processor-macros – Vee May 03 '16 at 13:32
  • I'm currently without a computer somewhere in Tokyo for a few days. I'll take a look next week if no one did. – Cai May 03 '16 at 21:14