简体   繁体   English

定义Visual Studio 2012 RC中ANSI C ISO / IEC-9899:1990中缺少的布尔类型

[英]Define boolean type absent in ANSI C ISO/IEC-9899:1990 in Visual Studio 2012 RC

typedef char bool;

doesn't work (Edit: it doesn't compile for "fatal error C1004: unexpected end-of-file found", not just about inference by Intellisense). 不起作用(编辑:它不会针对“致命错误C1004:发现意外的文件结尾”进行编译,而不仅仅是Intellisense的推断)。 Reason I assume is that bool is one of the reserved keywords in Microsoft Visual C/C++. 我认为的原因是bool是Microsoft Visual C / C ++中的保留关键字之一。 Since I need boolean type of literal name as exact "bool" (That means, type names other than bool, such as 由于我需要使用文字类型名称的布尔类型作为精确的“ bool”(即,键入除bool之外的其他名称,例如

boolean
BOOLEAN
BOOL
Bool
...

are not allowed ), is there a compiling option perhaps I can use to override the keyword "bool" which is NOT in ANSI C(ISO/IEC-9899:1990) Microsoft Visual C/C++ complies with? 是不允许的 ),有没有编译选项也许我可以用它来替换关键字“布尔”这是不是在ANSI C(ISO / IEC-9899:1990)微软的Visual C与/ C ++的规定?

NB: THIS IS NOT ABOUT C++ or VISUAL C++ AT ALL. 注意:这根本不涉及C ++或VISUAL C ++。 IT'S ABOUT PROGRAMMING IN ANSI C 90 WITH MSVC COMPILER IN COMPATIBLE MODE. 关于在兼容模式下使用MSVC编译器在ANSI C 90中进行编程。

Thanks in advance. 提前致谢。

Supplementary 补充

Compiling option: /TC /Za 编译选项:/ TC / Za

/* ANSI C file main.c */

typedef char bool;

int main(int argc, char * argv[])
{
    return 0;
}

(Edit: This problem has been figured out. For this case - typedef char bool - in terms of ANSI C, one can't disable Microsoft language extension by setting /Za option to work around, though Microsoft suggests the opposite. Such incoherence might be treated as a potential bug in Visual Studio 2012 RC) (编辑:已经解决了此问题。对于这种情况-typedef char bool-就ANSI C而言,不能通过设置/ Za选项来解决方案来禁用Microsoft语言扩展,尽管Microsoft建议相反。这样的不一致可能被视为Visual Studio 2012 RC中的潜在错误)

There is an option for the the file where you can choose what type to compile as (you can choose C or C++) 该文件有一个选项,您可以在其中选择要编译的类型(可以选择C或C ++)

Also, have you tried stdbool.h 另外,您是否尝试过stdbool.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM