4

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?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
eonil
  • 83,476
  • 81
  • 317
  • 516
  • 1
    possible duplicate of [What's the difference between GNU99 and C99?](http://stackoverflow.com/questions/5313536/whats-the-difference-between-gnu99-and-c99) – Paul R Mar 15 '11 at 15:08
  • 3
    @Paul I don't think so. I'm curious just what the term *ANSI C* in the list specifies. The question at the link is about specific difference about GNU99 and C99. I modified the title to describe my question better. – eonil Mar 15 '11 at 15:15
  • Can you find out what compiler options xcode actually passes to gcc for "ANSI C" vs "C89"? Then we can answer with reference to GCC alone, which would be easier for those of us who've never used xcode. Normally "ANSI C" means either ANSI C89 or ISO C90, two publications which are supposed to be functionally identical but with changes in e.g. pagination between the two, but it doesn't necessarily follow that xcode means the same thing by both. – Steve Jessop Mar 15 '11 at 15:40
  • This assuming it's using gcc, not clang. Anyway, if I had to guess I'd guess that "C89" means `-std=c89` and "ANSI C" means `-std=c89 -pedantic`, since that's the most useful distinction I can think of drawing without the names being totally inappropriate. – Steve Jessop Mar 15 '11 at 15:44
  • 2
    @Steve: That's not what it means. The dialect selection box actually shows what each option means in terms of the flag to GCC: http://dl.dropbox.com/u/14571816/xcodelang.png – Nicholas Knight Mar 15 '11 at 15:54
  • @Nicholas: that's not the most useful distinction I can think of then, since for GCC, `-ansi` and `-std=c89` are equivalent. Thanks! – Steve Jessop Mar 15 '11 at 16:54

4 Answers4

6

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.

wkl
  • 77,184
  • 16
  • 165
  • 176
1

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)

pmg
  • 106,608
  • 13
  • 126
  • 198
  • Right, but ISO C90 isn't an option on that list. My guess is that `ANSI C` is in this case a synonym for `C89`. http://en.wikipedia.org/wiki/ANSI_C – mbauman Mar 15 '11 at 15:33
  • So... can we conclude that ANSI C means C89 and the Xcode IDE is messing up something? – SubniC Mar 15 '11 at 15:33
  • Are there any differences between C89 and C90? My understanding was that there were no technical differences at all, but I could be wrong. – James McNellis Mar 15 '11 at 15:43
  • @James - There are no differences between C89 or C90 in terms of the C language specifications. The standards documents (ANSI C89 and ISO C90) are different in how sections are numbered. – wkl Mar 15 '11 at 15:46
  • In GCC documentation, option `-ansi` is just equivalent with `-std=c90` and also specified `c89` is equivalent with `c90` in `-std` flag. So I believe GCC will handle `-ansi`, `-std=c89` and `-std=c90` equally. – eonil Mar 16 '11 at 04:24
1

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.

Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
  • +1 for compatibility description. I had worried about compatibility once, and I got the answer now :) – eonil Mar 16 '11 at 04:28
0

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

Nicholas Knight
  • 15,774
  • 5
  • 45
  • 57
  • Chosen as the answer for link to reference documentation. Xcode uses GCC or Clang, and Clang accept GCC options. So now I can sure ANSI C means ANSI C89 which is just equivalent with ISO C90. In my opinion, Apple made the option without serious consideration. – eonil Mar 16 '11 at 04:20