views:

1338

answers:

6

How universally is the C99 standard supported in today's compilers ? I understand that not even GCC fully supports it. Is this right ?

Which features of C99 are supported more than others, i.e. which can I use to be quite sure that most compilers will understand me ?

Thanks

+4  A: 

For gcc, there is a table with all supported features. It seems to be that the biggest thing missing are variable-length arrays. Most of the other missing features are library issues rather than language features.

Torsten Marek
+3  A: 

Look at C99 suport status for GNU for details on which features are supported currently.

Sun Studio is purported to support the entire C99 spec. I have never used them, so I can't confirm.

I don't believe the microsoft compiler supports the C99 spec in its entirety. They are much more focused on C++ at the moment

Benoit
+12  A: 

If you want to write portable C code, then I'd suggest you to write in C89 (old ANSI C standard). This standard is supported by most compilers. If you're looking for C99, then you need Intel C Compiler. It has full C99 support and it produces fast binaries.

GCC supports some new things of C99. They created a table about the status of C99 features. Probably the most usable feature of C99 is the variable length array, and GCC supports it now.

Most commercial (like MSVC) compilers are focused on C++, so they won't support C99 in the future neither.

KovBal
By ANSI C, do you mean C89/C90 ? Because ANSI C and ISO C used to be synonymous, but I understand that now ISO C refers to C99
Eli Bendersky
GCC 4.5 finally lists variable length arrays as *Done* and not *Broken*!
kaizer.se
@kaizer.se : Thanks for letting us know.
KovBal
Mu question could also bring you some relevant info on this topic: http://stackoverflow.com/questions/3093049/different-behavior-of-compilers-with-array-allocation
PeterK
variable length arrays are broken in GCC 4.2 (for anyone using xcode 3.2.3 as standard)
Remover
+2  A: 

Microsoft appear to be tracking C++ standards, but have no support for C99. (They may cherry-pick some features, but could be said to be cherry-picking C++0x where there's an overlap.)

As of Visual Studio .NET 2003, new projects have the 'Compile C code as C++ (/TP)' option enabled by default.

Mike Dimmick
+5  A: 

Someone mentioned the Intel compiler has C99 support. There is also the Comeau C/C++ compiler which fully supports C99. These are the only ones I'm aware of.

C99 features that I do not use because they are not well supported include:

  • variable length arrays
  • macros with variable number of parameters.

C99 features that I regularly use that seem to be pretty well supported (except by Microsoft):

  • stdint.h
  • snprintf() - MS has a non-standard _snprintf() that has serious limitations of not always null terminating the buffer and not indicating how big the buffer should be

To work around Microsoft's non-support, I use a public domain stdint.h from MinGW (that I modified to also work on VC6) and a nearly public domain snprintf() from Holger Weiss

Items that are not supported by Microsoft, but will still use on other compilers depending on the project include:

  • mixed declarations and code
  • inline functions
  • _Pragma() - this makes pragmas much more usable
Michael Burr
+1  A: 

The IBM c compiler has c99 support when invoked as c99 but not when invoked as cc or xlc.

frankster