简体   繁体   中英

Unwanted sal.h warnings

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?

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

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:

  • wrap the #include directives with pragmas to disable the warning while they're being included and reenable them afterward
  • submit a bug report to MS at the Visual Studio connect site
  • use some other runtime library (maybe Dinkumware will let you compile ANSI clean?)
  • give up on disabling extensions (I'd like to know if anyone successfully uses that option for more than small demonstrations or experiments)

or 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM