Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 reason about it's on there. What's the term ANSI C specifies in there?

like image 859
eonil Avatar asked Feb 25 '23 19:02

eonil


2 Answers

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.

like image 166
逆さま Avatar answered Apr 27 '23 15:04

逆さま


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.

like image 42
Hassan Syed Avatar answered Apr 27 '23 15:04

Hassan Syed