Has TRUE always had a non-zero value?

前端 未结 22 1038
予麋鹿
予麋鹿 2020-12-31 01:38

I have a co-worker that maintains that TRUE used to be defined as 0 and all other values were FALSE. I could swear that every language I\'ve worked with, if you could even

22条回答
  •  清酒与你
    2020-12-31 01:43

    For languages without a built in boolean type, the only convention that I have seen is to define TRUE as 1 and FALSE as 0. For example, in C, the if statement will execute the if clause if the conditional expression evaluates to anything other than 0.

    I even once saw a coding guidelines document which specifically said not to redefine TRUE and FALSE. :)

    If you are using a language that has a built in boolean, like C++, then keywords true and false are part of the language, and you should not rely on how they are actually implemented.

提交回复
热议问题