The container which can be a byte, a word, a dword or a qword, is totally irrelevant. The only thing that matters is a single bit, one the compiler chose to represent the boolean value.
No. Having one bit to represent two states and disregard other bits would have been a valid way to represent boolean, had it be chosen. There are other valid ways to store boolean too.
As documented, the chosen way is that the size is one byte (I hope you don't oppose the one byte choice for size, do you?) and that zero in all bits represent false value and 1 in bit 0, together with zeros in all other bits represents true value. All other 254 possible values of the boolean value, that is all values which have any bit other than bit 0 set, are undefined. This choice is perfectly valid.
And when this choice was made, it was so that the relation
False < True equals
True.
This relation is documented, so it must not be violated, keep that in mind when suggesting to treat any byte with bit 0 set to 1 as True.
FPC does NOT implement booleans, it implements C's BOOL. When it comes to the boolean type, it only works as long as it is considered a BOOL and NOT a boolean.
No. In fpc Boolean is what fpc documentation says, nothing else. And what you mean by "booleans" there remains unclear.
- in C, any non-zero value means True. It is not so with Boolean in fpc. Although you might experience the behaviour which appear so, it is not documented and, unlike in C, you must not rely on it.
- in FPC valid Boolean values are comparable -
false < true - you can rely on it. Not so in C.
The types from other languages have nothing to do with how Boolean is defined in FPC. There are types in FPC which are documented to behave like C, but not Boolean.
That's the reason why when using booleans, FPC can end up in situations where TRUE <> TRUE
This situation is not
True <> True
, it is
oneVariableWithUndefinedValue someRelationOperator anotherVariableWithUndefinedValue
You can't expect a predictable value from this expression. You get something once, another time something else. Or even worse, you will get the same outcome always, and your user something else.
but, when the compiler does that atrocity, it's "undefined territory" (but, of course, it is!) just like when a drunk drives into a tree, it's the tree that got in the way (obviously!.)
That's how it works, you need to take care yourself to avoid the crash. But you are in control, and as long as you don't overuse alcohol when programming, the tree doesn't get in the way.