问题描述
在构建设置"选项卡下的"Apple LLVM 7.0-预处理"部分中,我将预处理器宏定义为:
In the "Apple LLVM 7.0 - Preprocessing" section under the "Build Settings" tab, I've defined a Preprocessor Macros as:
STR(arg)=#arg
HUBNAME=STR("myhub")
HUBLISTENACCESS=STR("Endpoint=sb://abc-xyz.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=JKLMNOP=")
在我的代码中,我试图将HUBLISTENACCESS的值称为字符串:
In my code, I'm trying to refer to the value of HUBLISTENACCESS as a string:
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:@HUBLISTENACCESS notificationHubPath:@HUBNAME];
但是我从Xcode收到有关集线器"初始化的错误消息:
But I'm getting errors from Xcode for the initialization of "hub":
无终止的函数式宏调用
程序中出现意外的'@'
Unexpected '@' in program
我怀疑预处理器宏中的HUBLISTENACCESS定义需要正确转义,但我尝试了一些尝试,但似乎无法正确解决.有人可以帮助我了解我在做什么错吗?
I suspect that the definition of HUBLISTENACCESS in the Preprocessor Macros needs to be properly escaped but I've tried a few things and can't seem to get it right. Can somebody help me understand what I'm doing wrong?
推荐答案
有一个非常明显的原因,您尝试执行失败的原因是:在HUBLISTENACCESS
中使用//
.与C中一样,//
之后的内容已被注释掉,因此在编译器方面,您的最后一行实际上是:
There's one very obvious reason why you were trying to do failed: you use //
in the HUBLISTENACCESS
. As in C, things after //
were commented out so in the aspect of the compiler, the last line of yours is actually:
HUBLISTENACCESS=STR("Endpoint=sb:
要测试它,只需删除一个斜杠,它将再次起作用.您正在做的事情就像尝试定义这样的事情:
To test it, just remove one slash and it will work again. What you were doing like trying to define things as such:
#define FOO //
我认为这是不可能的.老实说,我不知道如何在 Build Settings 中进行操作,但是还有其他方法可以通过 PCH文件(前缀标头)在全球范围内进行操作.
which I don't think it's possible. I honestly have no idea how you can do that within the Build Settings, but there are other ways to do it globally via a PCH file (prefix header).
PCH中的一条简单的线将节省所有这些麻烦:
A simple line within the PCH will will save all those troubles:
#define HUBLISTENACCESS @"Endpoint=sb://abc-xyz.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=JKLMNOP="
然后按以下方式使用它:(不再需要@
!)
Then use it as below: (no more @
needed!)
NSLog(@"%@", HUBLISTENACCESS);
这篇关于Xcode LLVM处理器宏的Stringify端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!