Is it preferable to use Integer or Long for boolean variables? And when would we want to use Integer instead of Long?
My understsnding is, since QB64 has no native Boolean tyoe, we use 0 for False and -1 for True, and we can use constants for readability:
So far I have declared my "boolean" variables as Integer:
However, I've seen it mentioned on here a few times that Long is "native" to QB64 "under the hood" and offers a slight performance benefit over Integer. If this is true, and assuming the extra memory needed for a Long instead of an Integer isn't an issue, do I want to declare my "boolean" variables as type Long rather than Integer?
And in general, other than saving memory, is there any reason you would want to use Integer instead of Long for numeric types where you just need to store values between -32,768 and 32,767 signed or 0-65,535 unsigned?
Much appreciated...
Update: I'd still like to know what people have to say, but it looks like Long does work for boolean, per this test program...
Print "1. Does Val work with Long?" sValue = "1256512"
Print " iValue=" + cstrl$
(iValue
)
Print "2. Does type Long work for boolean values?"
bValue = (10 > 5)
Print " (10 > 5) evaluates to " + cstrl$
(bValue
)
bValue = (5 > 10)
Print " (5 > 10) evaluates to " + cstrl$
(bValue
)
bValue = ((2 + 2) = 5)
Print " ((2 + 2) = 5) evaluates to " + cstrl$
(bValue
)
bValue = ((2 + 2) = 4)
Print " ((2 + 2) = 4) evaluates to " + cstrl$
(bValue
)
bValue
= (5 > 3) Or (2 < 1)Print " (5 > 3) Or (2 < 1) evaluates to " + cstrl$
(bValue
)
bValue
= (5 > 3) And (2 < 1)Print " (5 > 3) And (2 < 1) evaluates to " + cstrl$
(bValue
)
' /////////////////////////////////////////////////////////////////////////////
Results:
1. Does Val work with Long?
sValue="1256512"
iValue=1256512
2. Does type Long work for boolean values?
(10 > 5) evaluates to -1
(5 > 10) evaluates to 0
((2 + 2) = 5) evaluates to 0
((2 + 2) = 4) evaluates to -1
(5 > 3) Or (2 < 1) evaluates to -1
(5 > 3) And (2 < 1) evaluates to 0
Finished.