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

Dri*_*Boy 23 c boolean

这是迄今为止我所包含的所有.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>
Run Code Online (Sandbox Code Playgroud)

哪个文件定义了bool

rlc*_*rlc 33

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


Nik*_*ntz 19

#include <stdbool.h>

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


pmg*_*pmg 16

bool只是一个宏是扩展到_Bool.您可以使用_Bool不带#include很像,您可以使用intdouble; 它是一个C99关键字.

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

定义的宏是

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