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

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org