如何在 Visual Studio 2015 中将头文件的编译器更改为 C 编译器(不是 C++) [英] How to change compiler for header to C compiler (not C++) in Visual Studio 2015

查看:58
本文介绍了如何在 Visual Studio 2015 中将头文件的编译器更改为 C 编译器(不是 C++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有

myheader.h

#include <stdbool.h>

_Bool foo()
{
    return true;
}

对于 cpp 文件,我可以将 *.cpp 更改为 *.c

For cpp files i can just change *.cpp to *.c

但是如何在 Visual Studio 2015 中将 头文件 的编译器更改为 C 编译器?

But how to change compiler for header file to C compiler in Visual Studio 2015?

推荐答案

"stdbool.h" 是一个 C99 头文件.Microsoft 的 C/C++ 编译器不支持它,而且可能永远不会支持. MSVC 2013 及更高版本似乎支持 C99.我的错.

"stdbool.h" is a C99 header file. Microsoft's C/C++ compiler doesn't support it, and probably never will. MSVC 2013 and above have C99 support it seems. My bad.

您可以:

  1. 寻找另一个编译器

  1. Find another compiler

使用黑客:

typedef int bool;
#define false 0
#define true 1

切换到 C++,它具有原生的 bool 类型.

Switch to C++, which has a native bool type.

我个人推荐第三个.

有关该主题的更多阅读:尝试使用 '#include '在 VS 2010 中

More reading on the topic here: trying to use '#include <stdbool.h>' in VS 2010

这篇关于如何在 Visual Studio 2015 中将头文件的编译器更改为 C 编译器(不是 C++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆