Why does clang's stdbool.h contain #define false false

后端 未结 2 776
借酒劲吻你
借酒劲吻你 2021-01-01 08:10

After being pointed there by a compiler error, I noticed clang\'s stdbool.h file includes (among other things) the following lines:

#define bool  bool
#defin         


        
2条回答
  •  天命终不由人
    2021-01-01 08:45

    It was added to suport GNU mode in C++, as we can see from this patch [cfe-commits] r115028 :

    Define _Bool, bool, true, and false macros in when we're in a GNU-compatible C++ dialect. Fixes .

    so gcc supports this as an extension and this modification was made to support that extension.

    Although I can not find the original problem report mentioned in the patch.

    This is non-conforming as we can see from the draft C++11 standard section 18.10 Other runtime support [support.runtime]:

    The header and the header shall not define macros named bool, true, or false.

    but gcc is not meant to be strictly conforming in GNU mode.

    stdbool.h is part of C99 and so was not supported by the C++ standard until C++11 which in Annex D says:

    For compatibility with the C standard library and the C Unicode TR, the C++ standard library provides the 25 C headers, as shown in Table 154

    and includes .

提交回复
热议问题