- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
在被编译器错误指出后,我注意到 clang 的 stdbool.h
文件包括(除其他外)以下几行:
#define bool bool
#define false false
#define true true
它们包含在 #ifdef
block 中,该 block 间接强制执行 __cplusplus
,因此即使 stdbool.h
是 C标题。
这些定义有什么需要?我想它们是某些与预处理器相关的原因所必需的,但我很想知道标准的哪一部分或哪个技术原因使它如此铿锵必须包括这些。
最佳答案
stdbool.h
是 C 头文件,而不是 C++ 头文件。它通常不会出现在 C++ 程序中,因为 true
和 false
在 C++ 中已经是关键字。
因此,如果 C++ 程序包含 stdbool.h
,则相当清楚地表明它是移植的 C 程序(例如,正在编译为 C++ 的 C 程序)。在这种情况下,G++ 支持 C++ 模式下的 stdbool.h
作为 GNU 扩展,根据来自 GCC stdbool.h
的评论。 :
/* Supporting <stdbool.h> in C++ is a GCC extension. */
#define _Bool bool
#define bool bool
#define false false
#define true true
...
/* Signal that all the definitions are present. */
#define __bool_true_false_are_defined 1
Clang 同样支持 C++ 中的 stdbool.h
以与 G++ 兼容。此处有意定义这些值以匹配内置 C++ 类型,而不是传统的 C99 定义。它们被定义为宏,大概是为了提供与 C99 standard 的兼容性。 ,这需要:
The header shall define the following macros:
bool
,true
,false
,__bool_true_false_are_defined
.An application may undefine and then possibly redefine the macros bool, true, and false.
关于c++ - 为什么 clang 的 stdbool.h 包含 #define false false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30875069/
我正在尝试读取击键然后停止代码。在 C 中。 #include #include #include #include bool starting() { char c; if (k
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 4 年前。 Improve t
我想在我的系统上找到 _Bool 定义,因此对于缺少它的系统我可以实现它。我在这里和其他网站上看到过各种关于它的定义,但我想检查系统以获得最终定义。 小问题,因为我找不到 _Bool 的定义位置,甚至
在 stdbool.h 中,true 和 false 只是整数。为什么不签名?有绩效动机吗? 最佳答案 使用类型 int对于值 false和 true使他们同意由逻辑否定运算符(!)、关系运算符(、=
假设我像这样在“struct.h”中定义一个结构 struct box { int value; } 我在另一个文件中使用该结构说“math.c” #include "struct.h" st
这是我的代码 主程序 #include #include #include "func.h" int main () { int counts = 10; printf("Expected
每当我需要 boolean 类型时,我都会被告知要么创建一个,要么使用 stdbool.h 更好。 由于 stdbool.h 使用 typedef bool _Bool,是否有理由使用 header
我不知道为什么会这样。有没有人遇到过这个?我使用的是 Netbeans 8.2,程序在 Debug模式下运行。 #include #include #include #define N 100
我还是 C 新手。我有一个关于源文件和头文件的问题。我有一个像这样的头文件: #ifndef MISC_H_ #define MISC_H_ #define BYTE 8 #include #inc
我的计算机科学老师给了我一个关于操作数组的作业模板。这包括 和图书馆。这两者似乎没有联系。使用该库时,我总是必须通过右键单击 Eclipse 文件资源管理器中的文件然后转到属性> C/C++ Buil
在一个项目中,我在 C++ 和一个使用 stdbool.h 定义的 C 库之间进行交互。 #ifndef _STDBOOL_H #define _STDBOOL_H /* C99 Boolean ty
我正在尝试在 C 程序中使用 stdbool.h 库文件。然而,当我尝试编译时,出现一条错误消息,指出智能感知无法打开源文件 stdbool.h。 谁能告诉我如何让 visual studio 识别这
我在 debian 上遇到了 eclipse cdt 3.8.0 格式化程序的问题。当它自动格式化我的代码时,函数返回 bool 和 block 注释之间的换行符被删除,如下所示:这是 C 源文件中的
在被编译器错误指出后,我注意到 clang 的 stdbool.h文件包括(除其他外)以下几行: #define bool bool #define false false #define true
我刚刚注意到 gcc 和 clang 似乎都对 stdint.h 使用 typedef,但对 stdbool.h 使用 #define。 示例:clang's stdint.h #ifdef __I
我正在尝试在 Solaris 上安装 Node.JS。这是开箱即用的 Solaris 9/10 x86(最新的是 2010 年 9 月)并且仅使用默认包。 我遵循的指示在这里:https://gith
我的印象是 C 或 C++ 中的 bool 类型是 typdef'ed 整数,因为它在机器级别(字的大小等)处理起来“更容易”。但我只是执行了一个 sizeof,令我惊讶的是,它们返回了 1(字节)。
我是一名优秀的程序员,十分优秀!