Build a Visual Studio 2013 project in pure C

2020-02-11 08:52发布

问题:

What is the best way to do this? The templates seem to allow only for C++ (which is basically compatible with C, but not the same.) What is the proper way to do this? (A particular #define or whatever.) Any help would be appreciated.

回答1:

The solution is simple and easy

  1. You create a new win32 console project

  2. Remove the default .cpp file

  3. Add new .c file as you wish

  4. In Properties, under C/C++ --> All Options, find "Compile as", then select "Compile as C code"

  1. Simple sanity check. This code doesn't work with C++ since "new" is a reserved word for C++.

    int new = 10;