访问 Xcode LLVM 处理器宏
Accessing Xcode LLVM Processor Macros
在 "Build Settings" 选项卡下的 "Apple LLVM 7.0 - Preprocessing" 部分,我将预处理器宏定义为:
HUBNAME=myhub
在我的代码中,我尝试将 HUBNAME 的值作为字符串引用:
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:HUBLISTENACCESS notificationHubPath:HUBNAME];
但是 Xcode 认为 'myhub' 是我的变量名:
Use of undeclared identifier 'myhub'
谁能帮我弄清楚如何以字符串形式访问 'myhub'?
类似TO_STR(arg)=#arg HUBNAME=TO_STR("myhub")
? (或者只是 TO_STR(myhub)
w/o 引用。)
NSLog(@"%s", HUBNAME); // SO36947532[13085:4401425] myhub
来自 GNU:
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.
在 "Build Settings" 选项卡下的 "Apple LLVM 7.0 - Preprocessing" 部分,我将预处理器宏定义为:
HUBNAME=myhub
在我的代码中,我尝试将 HUBNAME 的值作为字符串引用:
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:HUBLISTENACCESS notificationHubPath:HUBNAME];
但是 Xcode 认为 'myhub' 是我的变量名:
Use of undeclared identifier 'myhub'
谁能帮我弄清楚如何以字符串形式访问 'myhub'?
类似TO_STR(arg)=#arg HUBNAME=TO_STR("myhub")
? (或者只是 TO_STR(myhub)
w/o 引用。)
NSLog(@"%s", HUBNAME); // SO36947532[13085:4401425] myhub
来自 GNU:
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.