Using true and false in C

后端 未结 15 1868
情书的邮戳
情书的邮戳 2020-12-01 01:52

As far as I can see there are 3 ways to use booleans in c

  1. with the bool type, from then using true and false
  2. defining using preprocessor #defin
15条回答
  •  粉色の甜心
    2020-12-01 02:39

    With the stdbool.h defined bool type, problems arise when you need to move code from a newer compiler that supports the bool type to an older compiler. This could happen in an embedded programming environment when you move to a new architecture with a C compiler based on an older version of the spec.

    In summation, I would stick with the macros when portability matters. Otherwise, do what others recommend and use the bulit in type.

提交回复
热议问题