7

I generally program & compile under Linux with gcc and -ansi flag; but I've been forced with doing a job in Visual C++ and whenever I compile my C code I get all the Microsoft warnings like

'fscanf': This function or variable may be unsafe. Consider using fscanf_s instead.

I get these despite following some steps on MSDN Developer's site for setting up an ANSI C project, but all the _s ("secure") calls are not ANSI C!

Any suggestions on putting Visual C++ Studio in a strict ANSI-only mode?

Thanks.

jparanich
  • 7,681
  • 4
  • 23
  • 30

3 Answers3

6

As mentioned in another answer, #define'ing _CRT_SECURE_NO_WARNING will address the specific warnings you mentioned in your question.

If you're really looking for an ANSI-only mode, the closest thing is the /Za compiler switch. Inside the Visual Studio IDE, you can find it in the project's Properties dialog (under Configuration Properties | C/C++ | Language | Disable Language Extensions).

Note that virtually all Windows apps build with Microsoft's compiler extensions enabled; e.g., I don't think you'd even be able to consume Windows SDK headers with /Za set. If your code truly is strict ANSI, you should be OK. If you have a few Windows-specific pieces in a project that is mostly strict ANSI, you could probably isolate those sources and only build those indivudal source files with /Za unset.

Andrew Brown
  • 4,067
  • 1
  • 22
  • 21
  • You are correct: `` and the `/Za` compiler switch hate each other. [Link to Microsoft Connect - Bug is *Closed*](http://connect.microsoft.com/VisualStudio/feedback/details/780509/including-windows-h-and-compiling-with-za-disable-language-extensions). – IInspectable Nov 12 '13 at 15:19
4

These warnings can be suppressed by defining _CRT_SECURE_NO_WARNING

Go to Procect Settings -> Preprocessor and add _CRT_SECURE_NO_WARNING

This isn't forcing compiler to comply with ANSI. Just suppresses use ..._s warnings

Matthieu M.
  • 268,556
  • 42
  • 412
  • 681
Armen Tsirunyan
  • 125,569
  • 56
  • 315
  • 427
2

One way to suppress specific warnings is to add something like the following to the source.

#if defined( _WIN32 )
#pragma warning(disable:4996)
#endif
Mark Wilkins
  • 40,032
  • 5
  • 54
  • 108