Using true and false in C

后端 未结 15 1861
情书的邮戳
情书的邮戳 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:17

    1 is most readable not compatible with all compilers.

    No ISO C compiler has a built in type called bool. ISO C99 compilers have a type _Bool, and a header which typedef's bool. So compatability is simply a case of providing your own header if the compiler is not C99 compliant (VC++ for example).

    Of course a simpler approach is to compile your C code as C++.

提交回复
热议问题