您在linux中使用哪个头文件在c中使用bool类型?

问题描述 投票:23回答:5

这是迄今为止我所包含的所有.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

c boolean
5个回答
31
投票

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


15
投票

bool只是一个扩展到_Bool的宏。你可以使用没有_Bool#include非常像你可以使用intdouble;它是一个C99关键字。

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

定义的宏是

  • bool:宏扩大到_Bool
  • false:宏扩大到0
  • true:宏扩大到1
  • __bool_true_false_are_defined:宏扩大到1

14
投票

#include <stdbool.h>

像我这样的人来复制和粘贴。


-4
投票

布尔运算的头文件n C是stdbool.h


-4
投票

在代码中尝试此头文件

stdbool.h

这必须奏效

© www.soinside.com 2019 - 2024. All rights reserved.