C语言 您包含哪个头文件以在 linux 中使用 c 中的 bool 类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6118846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 08:45:21  来源:igfitidea点击:

Which header file do you include to use bool type in c in linux?

cboolean

提问by DriverBoy

Here's all .h files I've included so far,but non have the definition of bool:

这是我到目前为止包含的所有 .h 文件,但没有定义bool

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
#include <event.h>

Which file does define bool?

哪个文件定义了bool

回答by rlc

It's part of C99and defined in POSIX definition stdbool.h.

它是C99的一部分,在POSIX 定义 stdbool.h定义

回答by Niklas

#include <stdbool.h>

#include <stdbool.h>

For someone like me here to copy and paste.

对于像我这样的人在这里复制和粘贴。

回答by pmg

boolis just a macrothat expands to _Bool. You can use _Boolwith no #includevery much like you can use intor double; it is a C99 keyword.

bool只是一个宏是扩展到_Bool。您可以使用_Boolno #include,就像您可以使用intor 一样double;它是一个 C99 关键字。

The macro is defined in <stdbool.h>along with 3 other macros.

该宏<stdbool.h>与其他 3 个宏一起定义。

The macros defined are

定义的宏是

  • bool: macro expands to _Bool
  • false: macro expands to 0
  • true: macro expands to 1
  • __bool_true_false_are_defined: macro expands to 1
  • bool: 宏扩展为 _Bool
  • false: 宏扩展为 0
  • true: 宏扩展为 1
  • __bool_true_false_are_defined: 宏扩展为 1

回答by Mayur Turuvekere

Try this header file in your code

在你的代码中试试这个头文件

stdbool.h

This must work

这必须工作