开发者

What's the term *ANSI C* specifies if it used with GNU89, C89, GNU99, C99?

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 r开发者_开发知识库eason about it's on there. What's the term ANSI C specifies in there?


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 various std= 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.

-ansi

In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98.

And if you use the -std flags, you can pass certain values to activate different language features.

-std=

Determine the language standard. This option is currently only supported when compiling C or C++.


These arguments are equivalent:

c90

c89

iso9899:1990 Support all ISO C90 programs (certain GNU extensions that conflict with ISO C90 are disabled). Same as -ansi for C code.


These arguments are equivalent:

iso9899:199409 ISO C90 as modified in amendment 1.


These following arguments are equivalent:

c99

c9x

iso9899:1999

iso9899:199x

ISO C99. Note that this standard is not yet fully supported; see http://gcc.gnu.org/gcc-4.5/c99status.html for more information. The names c9x and iso9899:199x are deprecated.


These following arguments are equivalent:

gnu90

gnu89

GNU dialect of ISO C90 (including some C99 features). This is the default for C code.


These following arguments are equivalent:

gnu99

gnu9x

GNU dialect of ISO C99. When ISO C99 is fully implemented in GCC, this will become the default. The name gnu9x is deprecated.


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 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)


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜