C 编程/stdbool.h
外观
< C 编程
C 编程语言的 C 标准库中的头文件 **stdbool.h** 包含用于布尔数据类型的四个宏。此头文件在 C99 中引入。
ISO C 标准中定义的宏是
- bool 展开为 _Bool
- true 展开为 1
- false 展开为 0
- __bool_true_false_are_defined 展开为 1
这可以在示例中使用
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void) {
bool keep_going = true; // Could also be `bool keep_going = 1;`
while(keep_going) {
printf("This will run as long as keep_going is true.\n");
keep_going = false; // Could also be `keep_going = 0;`
}
printf("Stopping!\n");
return EXIT_SUCCESS;
}
这将输出
This will run as long as keep_going is true. Stopping!
- : 布尔类型和值 – 基础定义参考,The Single UNIX® Specification,来自 The Open Group 的 Issue 7