True and false

Give it a try, it costs you nothing !
Post Reply
bugs
Posts: 148
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 55 times
Been thanked: 58 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: 9
Joined: Tue Feb 09, 2021 12:59 pm
Has thanked: 36 times
Been thanked: 2 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: 947
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 310 times
Been thanked: 352 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: 9
Joined: Tue Feb 09, 2021 12:59 pm
Has thanked: 36 times
Been thanked: 2 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: 361
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 197 times
Been thanked: 115 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: 2195
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 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