Reputation: 6211
I'm trying to use VS 2008 for compiling some C code. I configured the project to use ANSI C standard without any language extensions. I also upped the warning level from 3 to 4.
Upon building the project I always get this warning:
c:\program files\microsoft visual studio 9.0\vc\include\sal.h(108) : warning C4001: nonstandard extension 'single line comment' was used
I understand the warning, but how do I get rid of it? I did not include sal.h anywhere. Also, when creating the solution I chose Win32 Console Application and checked the "Empty Project" checkbox.
EDIT: I enabled the /showIncludes switch as suggested, but it doesn't really help since it does not show what includes what. It seems that VS includes a bunch of stuff on its own:
Compiling...
go.c
Note: including file: c:\projects\c\kr\kr\e.01.01.h
Note: including file: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdio.h
Note: including file: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
Note: including file: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h
c:\program files\microsoft visual studio 9.0\vc\include\sal.h(108) : warning C4001: nonstandard extension 'single line comment' was used
Note: including file: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtassem.h
Note: including file: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vadefs.h
Note: including file: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\swprintf.inl
Linking...
Am I missing some compiler switch?
Upvotes: 4
Views: 3073
Reputation: 340218
Unfortunately you're kind of stuck - Microsoft's runtime headers seem to use single line comments in more than just sal.h
(for example, stdlib.h
uses them, too), so you can either:
#include
directives with pragmas to disable the warning while they're being included and reenable them afterwardor some combination of the above.
Option #1 is likely to get you going pretty easily:
#pragma warning( push)
#pragma warning( disable : 4001)
#include <stdlib.h>
/* other runtime includes */
#pragma warning( pop)
But I wouldn't be at all surprised if there are other non-ANSI things in the runtime headers. It looks like they've made some attempt to be ANSI clean for when the option was given, but I suspect it's not heavily tested (particularly at non-default warning levels).
Upvotes: 2
Reputation: 14341
#pragma warning( disable:4001)
Put this somewhere to be compiled before the lines with problems.
For more details, see #pragma warning documentation in MSDN.
Later edit
Use the option from Visual C++ to display the include files when compiling (it should be somewhere in the advanced options in C++ section). It can provide an idea where sal.h is included. Probably some of the VC libraries include this header indirectly. If it is a C header, I wonder why they used C++ style comments...
Upvotes: 2