加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

在没有Microsoft扩展的情况下构建Visual C

发布时间:2020-12-14 02:21:49 所属栏目:Windows 来源:网络整理
导读:参见英文答案 /Za compiler directive does not compile system headers in VS2010????????????????????????????????????2个 我正在尝试在Microsoft Visual C 2013中构建一个禁用所有非标准扩展的项目. #ifdef _MSC_VER#include windows.h#endif 在配置属性
参见英文答案 > /Za compiler directive does not compile system headers in VS2010????????????????????????????????????2个
我正在尝试在Microsoft Visual C 2013中构建一个禁用所有非标准扩展的项目.

#ifdef _MSC_VER
#include <windows.h>
#endif

在配置属性中 – > C/C++ – >语言,我将“禁用语言扩展”设置为是(/ Za).
但是,构建以前的代码我得到的错误如下:

C:Program Files (x86)Windows Kits8.1Includeumwinnt.h(11527):
error C2467: illegal declaration of anonymous ‘struct’

这意味着仍然定义了_MSC_VER宏,并且已经包含了“windows.h”.

当且仅当我使用Visual C时,如何包含文件?

如何设置Visual C以便将代码编译为标准C,将所有Microsoft扩展标记为错误?

解决方法

How can I include a file if and only if I am using Visual C++?

如您所示,通过检查_MSC_VER.

How can I set Visual C++ so that it compiles the code as Standard C++,marking all Microsoft extensions as errors?

你不能.我不知道任何允许这样做的编译器.编译器版本的预定义宏等标准完全允许,因此它们不会被禁用为“非标准扩展”.

如果要检查您的程序是否为其他平台构建,请在其他平台上构建程序. GCC和Clang会告诉你他们接受的东西远比Visual C会好:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读