Using true and false in C

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

    There is no real speed difference. They are really all the same to the compiler. The difference is with the human beings trying to use and read your code.

    For me that makes bool, true, and false the best choice in C++ code. In C code, there are some compilers around that don't support bool (I often have to work with old systems), so I might go with the defines in some circumstances.

提交回复
热议问题