如果与 GNU89、C89、GNU99、C99 一起使用,术语 *ANSI C* 指定什么?
在 Xcode IDE 中,我可以选择将 C 语言方言设置为
- ANSI C
- GNU89
- C89
- GNU99
- C99
- 编译器默认值
之一。我理解除 ANSI C 之外的它们的含义。因为据我所知,ANSI C 只是 C89 或 C99 之一。但它的存在应该是有原因的。其中的术语 ANSI C 指定了什么?
In Xcode IDE, I have an option to set C language dialect one of
- ANSI C
- GNU89
- C89
- GNU99
- C99
- Compiler Default
I understand what they mean except ANSI C. Because As I know, ANSI C is just one of C89 or C99. But there should be a reason about it's on there. What's the term ANSI C specifies in there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编辑 感谢 @Nicholas Knight 发布了 XCode 的 C 方言选择窗口的屏幕截图:http://dl.dropbox.com/u/14571816/xcodelang.png
ANSI C 在历史上指的是 ANSI C89 标准(实际上与 C90 相同) )。 XCode 使用 GCC 版本作为编译器后端来编译 C 代码,所以我认为这就是他们获取这些“选项”的地方,因为您可以指定
-ansi
标志或各种std=
标志来选择 C 编译器后端编译代码时应使用的模式。因此,如果您传递它
-ansi
,并使用C编译器,它相当于-std=c90
,这也相当于-std=c89
代码> 或<代码>-std=iso9899:1990。如果您使用
-std
标志,则可以传递某些值来激活不同的语言功能。这些参数是等效的:
这些参数是等效的:
以下参数是等效的:
以下参数是等效的:
以下参数是等效的:
edit Credit goes to @Nicholas Knight for posting a screenshot from XCode's C dialect selection window: http://dl.dropbox.com/u/14571816/xcodelang.png
ANSI C refers, historically, to the ANSI C89 standard (practically the same thing as C90). XCode uses a version of GCC as the compiler back-end for compiling C code, so I think that's where they get these 'options' from, as you can specify the
-ansi
flag or variousstd=
flags to choose the mode the C compiler backend should operate in for compiling your code.So if you pass it
-ansi
, and using the C compiler, it's equivalent to-std=c90
, which is also equivalent to-std=c89
or-std=iso9899:1990
.And if you use the
-std
flags, you can pass certain values to activate different language features.These arguments are equivalent:
These arguments are equivalent:
These following arguments are equivalent:
These following arguments are equivalent:
These following arguments are equivalent:
编译器有他们所针对的语言的配置文件,就像 pmg 在他的回复中所说的那样,ANSI C 是最早的配置文件之一,K&R 书中描述的配置文件。
有趣的问题是,为什么编译器要维护遗留语言配置文件列表?因为,根据 ANSI C 配置文件编写代码可以有力地保证您的代码几乎可以与任何编译器(更重要的是编译器版本)一起使用。
当软件项目声称具有 ANSI-C 兼容性时,他们是在告诉您,无论如何,它都可以在任何地方进行编译。 Lua的源代码就是一个例子。
Compilers have profiles of the languages they are targeting, like pmg said in his reply ANSI C was one of the earliest profiles, the one that is described in the K&R book.
The question of interest is, why do compilers maintain a list of legacy language profiles ? Because, writing code against the ANSI C profile is quite a strong guarantee that your code will work with virtually any compiler (more importantly compiler version).
When software projects claim ANSI-C compatibility they are telling you that it will compile everywhere give-or-take. Lua's source code is an example of this.
C“诞生”于70年代。
1978 年,布莱恩·科尼汉 (Brian Kernighan) 和丹尼斯·里奇 (Dennis Ritchie) 出版了这本书。本书(第一版)中描述的语言现在称为“K&R C”。
1988年左右,出版了第二版。这个第二版与 ANSI (ISO) 标准非常非常相似,并且是人们在提到本书时通常谈论的版本:)
编译器作者开始对语言进行更改,并且,为了使其标准化,ANSI于1989年发布了一个标准(C89标准或ANSI C)。紧随其后的是 ISO 标准 (C90),该标准几乎没有对 ANSI 进行任何更改。
1999年,ISO发布了另一个C标准:我们称之为C99。
因此,如果我是对的,ANSI C 只流行了几个月,但 ANSI C 和 ISO C90 之间的差异很小。事实上,今天的许多编译器都是带有附加功能的 ANSI C 编译器(而不是带有附加功能但没有一些东西的 ISO C99 编译器)
C was "born" in the 70's.
In 1978 Brian Kernighan and Dennis Ritchie published the book. The language as described in the book (the 1st edition) is now called "K&R C".
In 1988 or so, there was a 2nd edition published. This 2nd edition is very, very similar to the ANSI (ISO) Standard, and is the edition that people talk about usually when referring to the book :)
Compiler writers started to make changes to the language and, in order to standardize it, ANSI published a Standard in 1989 (The C89 Standard or ANSI C). This was shortly followed by the ISO standard (C90) which makes hardly any changes to the ANSI.
In 1999, ISO published another C Standard: What we call C99.
So, if I'm right, ANSI C was current only for a few months, but the difference between ANSI C and ISO C90 is minimal. In fact, many compilers today are compilers for ANSI C with extras (rather than for ISO C99 with extras but without a few things)
事实上,假设您使用 GCC 作为编译器,则 ANSI 和 C89 是同一事物的别名。请参阅:
http://gcc.gnu.org /onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options
为什么苹果做出设计决定来呈现它们两者,我不确定。 GCC 中没有实际区别。也许他们担心 -ansi 的含义在 GCC 的后续版本(可能是 C99)中发生变化。
Assuming you are, in fact, using GCC as the compiler, ANSI and C89 are aliases for the same thing. See:
http://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options
Why Apple made the design decision to present them both, I'm not sure. There is no practical distinction in GCC. Perhaps they're being paranoid in case the meaning of -ansi changes in later versions of GCC (perhaps to C99).