Has TRUE always had a non-zero value?

前端 未结 22 821
予麋鹿
予麋鹿 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 02:00

    It's easy to get confused when bash's true/false return statements are the other way around:

    $ false; echo $?
    1
    $ true; echo $?
    0
    
    0 讨论(0)
  • 2020-12-31 02:01

    General rule:

    1. Shells (DOS included) use "0" as "No Error"... not necessarily true.

    2. Programming languages use non-zero to denote true.

    That said, if you're in a language which lets your define TRUE of FALSE, define it and always use the constants.

    0 讨论(0)
  • 2020-12-31 02:03

    In any language I've ever worked in (going back to BASIC in the late 70s), false has been considered 0 and true has been non-zero.

    0 讨论(0)
  • 2020-12-31 02:05

    In languages like C there was no boolean value so you had to define your own. Could they have worked on a non-standard BOOL overrides?

    0 讨论(0)
提交回复
热议问题