简体   繁体   English

在Xcode中使用c89

[英]Using c89 in Xcode

Is there any way to compile C code with c89 standard NOT c99 in Xcode (or another way with terminal)? 有什么方法可以在Xcode中用c89标准NOT c99编译C代码(或者用终端的另一种方法)?

I've searched in Xcode settings but I didn't find any way to choose compiler or standard. 我已经在Xcode设置中进行搜索,但是找不到任何选择编译器或标准的方法。

You should add -pedantic-errors to Other C flags in your project settings, like so: 您应该在项目设置中的其他C标志中添加-pedantic-errors ,如下所示:

解

Of course, don't forget to set the C language dialect to C89 as well. 当然,也不要忘记将C语言方言也设置为C89

This will give you the appropriate compile time errors when you try to compile something that is not valid C89. 当您尝试编译无效的C89时,这将为您提供适当的编译时错误。

Optionally, if you want Xcode to compile your code regardless of incompatibilities, but only give you yellow warnings at the problematic lines, use -pedantic instead of -pedantic-errors . 可选地,如果您希望Xcode在不兼容的情况下编译您的代码,而只在出现问题的行上发出黄色警告,请使用-pedantic而不是-pedantic-errors

In a nutshell, these flags make the compiler stick to the language standard more strictly, as opposed to the default behavior, which is to attempt compiling the code any way possible. 简而言之,这些标志使编译器更加严格地遵循语言标准,这与默认行为相反,默认行为是尝试以任何可能的方式编译代码。

I hope this helps :) 我希望这有帮助 :)

Source (even though they mention this in the context of GCC, but the same flags apply for Clang as well) 来源 (尽管他们在GCC的上下文中提到了这一点,但相同的标志也适用于Clang)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM