views:

109

answers:

1

Hi, I read with interest the post "How universally is C99 supported ?". One of the comments therein points that Microsoft doesn't support C99. But the comment symbol // works with VS 2008 and this symbol is in C99. I have two questions:

  1. To what extent VS 2008 support C99?

  2. Is it ok in the same code to mix C89 and C99 syntax together? So if I write my code in C89 and then place a comment //. This means that I have mixed-coding. So what does the compiler do in such a case? Check my code first with c89 and then with C99 to accept that I use // for commenting?

Thanks a lot...

A: 

MSVC supports very little of C99 in C mode. The few things that it does (like '//' comments) are really extensions they've added to C90 mode that come from C++, which may happen to also be in C99. When compiling C code, MSVC treats '//' comments as an extension to C90, not that you're intermixing C90 code with C99 code.

You'll get 'better' C99 support by compiling your C files as C++ - in that way you'll get declarations that can be interspersed with statements and variable declarations in for statements that are scoped to the for loop, for example.

Microsoft seems to have zero interest in adding C99 support to MSVC - even as they add things from C99 to the C++ compiler mode (like stdint.h being added in VS2010) since some additional C99 things are being added to C++ in C++0x.

Michael Burr
Thanks. I normally save my files with an extension c instead of cpp as I work in C. Does the extension makes a difference for the compiler? Strangely, it's not mentioned that MSVC has a C compiler; It just mentions C++ compiler.
yCalleecharan
The extension makes a difference by default - .c files are compiled in C mode, .cpp and .cxx files are compiled in C++ mode. You can override this using the `/TP` or `/Tp<file>` to force compiling as C++ and `/TC` or `/Tc<file>` to force compiling as C: http://msdn.microsoft.com/en-us/library/032xwy55.aspx
Michael Burr
This is interesting to know. Thanks.
yCalleecharan