Using true and false in C

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

    Any int other than zero is true; false is zero. That way code like this continues to work as expected:

    int done = 0;   // `int` could be `bool` just as well
    
    while (!done)
    {
         // ...
         done = OS_SUCCESS_CODE == some_system_call ();
    }
    

    IMO, bool is an overrated type, perhaps a carry over from other languages. int works just fine as a boolean type.

提交回复
热议问题