[personal profile] kpreid

(I'm posting this because I have the feeling it is not as well known as it should be.)

If you're compiling a C program with GCC, unless you have a reason to do otherwise (such as compatibility with other compilers), use -std=c99 instead of -ansi. -ansi specifically chooses the older C90 standard.

Why should you use C99? I'm not one to give you a complete list of changes (this article seems to be decent for that), but my favorite features are:

  • Boolean and complex number types
  • Variable declarations may be freely intermixed with statements, and used in the first expression of a for loop
  • // line comments
  • Variable-length arrays
  • Inline structure initializers: foo((struct bar){...});
  • Using field names or array indexes in structure initializers: struct bar g = { .x = 0, .y = 9.81 };

Note that many of these are common extensions to C (which would be rejected by -ansi -pedantic, I believe), but C99 makes them standard. C99 also removes some archaic features/looseness so as to make it harder to accidentally write incorrect programs.