True and false

Give it a try, it costs you nothing !
Post Reply
bugs
Posts: 186
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 91 times
Been thanked: 75 times

True and false

Post by bugs »

Hi,

Not a vital requirement but would be "nice". :|

Currently I set variables False=0 and True=-1 at the start of most programs.
At one point I tried False=0 and True=NOT False - took me a while to debug that error...
Any chance of having embedded constants for TRUE and FALSE?
User avatar
Dompie
Posts: 56
Joined: Tue Feb 09, 2021 12:59 pm
Has thanked: 65 times
Been thanked: 14 times

Re: True and false

Post by Dompie »

I thought True/False is a bit variable so False=0 and True=1 and you can use it in bitwise commands. But maybe this isn't valid for Annex.
User avatar
Electroguard
Posts: 1094
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 373 times
Been thanked: 392 times

Re: True and false

Post by Electroguard »

Something to consider is what would be the value for true and false, which is only a useful adopted convention which can vary.
I use 'flag' variables at the top of the script which can be set =0 to disable something, or =1 to enable it (and sometimes set to higher numbers to change behaviour etc)... so like Bugs, in that context 0=off or false, and 1=true or active.

Things like EspNow functions that return a value; where 0=ok, but non-zero indicates that an error has occurred... so in that context 0=true, and 1 (or any non-zero) denotes false.

If there's logical argument for true=0 false=1 and for false=0 true=1, then as in politics, there's no universally accepted value of true and false.
User avatar
Dompie
Posts: 56
Joined: Tue Feb 09, 2021 12:59 pm
Has thanked: 65 times
Been thanked: 14 times

Re: True and false

Post by Dompie »

There is a difference between the logical True/False and an errorcode, 0=no error other value is an error.
BeanieBots
Posts: 565
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 331 times
Been thanked: 184 times

Re: True and false

Post by BeanieBots »

A debate that could go on forever. Many other languages actually use -1 for false.
As dompie points out, using bitwise logic is another ball-game when the value becomes important if it is to be used in boolean logic.
Personally, I'm not greatly fussed, but I think it requires a bit of thought if they are to be made constants.
User avatar
cicciocb
Site Admin
Posts: 3126
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 635 times
Been thanked: 2228 times
Contact:

Re: True and false

Post by cicciocb »

In annex rds false is 0 and true is any other value. This is how the C works.
Post Reply