Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 缺少桥接转换会在预处理源中导致错误,但在实际源中不会导致错误_Objective C_Automatic Ref Counting - Fatal编程技术网

Objective c 缺少桥接转换会在预处理源中导致错误,但在实际源中不会导致错误

Objective c 缺少桥接转换会在预处理源中导致错误,但在实际源中不会导致错误,objective-c,automatic-ref-counting,Objective C,Automatic Ref Counting,要编译源文件,clang首先对其进行预处理,然后再进行编译。因此,如果我运行clang-E,我应该会得到一个经过预处理的文件,它可以用clang-c编译。但是下面的代码在预处理后不会编译 int main(int argc, char * argv[]) { NSString* foo = @"bar"; CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes( NULL,

要编译源文件,clang首先对其进行预处理,然后再进行编译。因此,如果我运行clang-E,我应该会得到一个经过预处理的文件,它可以用clang-c编译。但是下面的代码在预处理后不会编译

int main(int argc, char * argv[])
{
    NSString* foo = @"bar";

    CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(
        NULL,
        (CFStringRef)foo,
        NULL,
        (CFStringRef)@"",
        kCFStringEncodingUTF8 );

    CFRelease(urlString);

    return 0;
}
它使用clang-c编译,忽略foo被转换为CFStringRef而不使用_桥。当代码被预处理时,它就不再编译了,并且clang抱怨缺少桥转换。是否有禁用此行为的标志或解决此问题的方法

Full-clang命令(用于使用-E进行编译和预处理)

叮当声-x目标-c-拱形臂V7S-F消息长度=0 -fdiagnostics show note包括stack-fmacro backtrace limit=0-std=gnu99-fobjc arc-Wno trigraphs-fpascal strings-Os-Wno missing field initializers-Wno missing prototype-Werror=return type-Wno implicit atomic properties-Werror=弃用的objc isa用法-Werror=objc root类-Wno receiver弱-Wno arc重复使用弱-Wduplicate method match-Wno missing brages-Wparenthes-Wswitch-Wunused function-Wno unused label-Wno unused parameter-Wunused variable-Wunused value-Wempty body-Wuninitialized-Wno未知pragmas-Wno shadow-Wno四字符常量-Wno转换-Wno转换-Wconstant转换-Wint转换-Wbool转换-Wenum转换-Wshorten-64-to-32-Wpointer sign-Wno newline eof-Wno selector-Wno strict selector match-Wundeclared selector-Wno弃用实现-DNS_BLOCK_断言=1-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -fstrict别名-Wprotocol-Wdeprecated声明-g-fvisibility=hidden-Wno符号转换-miphoneos version min=7.0-c main.m

比较: “CFStound.h”和其他核心基础标头包含宏

CF_IMPLICIT_BRIDGING_ENABLED
...
CF_IMPLICIT_BRIDGING_DISABLED
扩展到

_Pragma("clang arc_cf_code_audited begin")
...
_Pragma("clang arc_cf_code_audited end")
这使得Clang不会抱怨缺少
\u桥
cast

pragmas被预处理器“消耗”,因此不在预处理程序中 文件 由于您正在转换预处理的源代码,因此可以添加 将这些pragma再次添加到预处理文件的开始/结束位置。
编译时将不会出现警告。

只将
\uu桥
添加到强制转换中如何?向我们展示您传递给clang的其余标志。我的猜测是,在一种情况下,您启用了ARC,而在另一种情况下,您没有启用。添加_桥对我来说不是一个选项,因为我正在对预处理的数据进行一些转换source@ElvissStrazdiņš:
clang-E main.m>main.i;叮当-x objective-c-c main.i
不会对我的Xcode 5.2发出任何警告。@MartinR:您应该启用ARC来查看错误,添加
-fobjc ARC
参数。谢谢,这对我帮助很大!我还测试了其他pragma,它们都是经过预处理后留下的,为什么会被消耗掉呢?你知道吗,有可能禁用这种行为吗?@elvisstrazdiņšš:我不知道。