繁体   English   中英

您包含哪个 header 文件以在 linux 中的 c 中使用 bool 类型?

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

这是我到目前为止包含的 all.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>

哪个文件定义bool

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

#include <stdbool.h>

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

bool只是一个扩展为_Bool的宏 您可以使用没有#include_Bool ,就像使用intdouble一样; 它是一个 C99 关键字。

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

定义的宏是

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

在您的代码中尝试此 header 文件

stdbool.h

这必须有效

暂无
暂无

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

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