Where is stdbool.h?

后端 未结 6 1865
温柔的废话
温柔的废话 2020-12-28 15:42

I want to find the _Bool definition on my system, so for systems where it\'s missing I can implement it. I\'ve seen various definitions for it here and on other

6条回答
  •  粉色の甜心
    2020-12-28 16:23

    _Bool is a predefined type in C99, much like int or double. You will not find the definition for int in any header file either.

    What you can do is

    • check the compiler is C99
    • if it is use _Bool
    • otherwise use some other type (int or unsigned char)

    For example:

    #if defined __STDC__ && defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
    /* have a C99 compiler */
    typedef _Bool boolean;
    #else
    /* do not have a C99 compiler */
    typedef unsigned char boolean;
    #endif
    

提交回复
热议问题