Difference between _Bool and bool types in C?

前端 未结 2 579
一个人的身影
一个人的身影 2020-11-29 06:34

Can anyone explain me what is the difference between the _Bool and bool data type in C?

For example:

 _Bool x = 1;
  bool y =         


        
相关标签:
2条回答
  • 2020-11-29 06:54

    There is no difference.

    bool is a macro that expands to _Bool in stdbool.h.

    And true is a macro that expands to 1 in stdbool.h

    0 讨论(0)
  • 2020-11-29 07:04

    These data types were added in C99. Since bool wasn't reserved prior to C99, they use the _Bool keyword (which was reserved).

    bool is an alias for _Bool if you include stdbool.h. Basically, including the stdbool.h header is an indication that your code is OK with the identifier bool being 'reserved', i.e. that your code won't use it for its own purposes (similarly for the identifiers true and false).

    0 讨论(0)
提交回复
热议问题