How to “simulate” C99 in Visual Studio for variables declaration

本秂侑毒 提交于 2019-12-18 19:38:21

问题


I'm using Visual Studio 2012 to develop simple Win32 C programs. I know that the VS compiler only supports C89, but I'd like to know if there is a way to override this limitation.

In particular I'd like to declare variables anywhere in my code, instead of only at the beginning of scope blocks (as C89 requires).

Thanks in advance.


回答1:


The choices I see:

  • stick with MSVC and switch to C++
  • stick with MSVC and use a precompiler that translates C99 to C90 (Comeau, c99-to-c89)
  • switch to a toolchain that supports more recent revisions of the C language (Intel, MinGW, Clang, Pelles-C,...)



回答2:


This seems like a dated thread, but having landed here first while I was searching for the same question I thought I should post an update:

As of VS13, the Visual C++ compiler supports C99 style variable declarations. More details here:

http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx




回答3:


Build your app using the C++ compiler. This is the easiest way. You can still write C code just name the file *.cpp



来源:https://stackoverflow.com/questions/13308944/how-to-simulate-c99-in-visual-studio-for-variables-declaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!