Prof A Olowofoyeku (The African Chief) wrote:
On 13 Dec 2002 at 12:33, CBFalconer wrote:
[...]
Indeed. But "Boolean (32)" doesn't create 32 1-bit Booleans but rather a single 32-bit variable with roughly Boolean semantics ("roughly" meaning that 0 is FALSE and all other values are TRUE). There is no way to achieve that directly using "packed" and the standard Boolean type.
And there is no need for such an entity. A logical expression such as "X = 0" or "X <> 0" covers it quite nicely. It also avoids the eternal C confusion about what IS a logical expression.
So why does Pascal have the Boolean type if we can just discard it in favour of a numerical comparison?
If we are to retain a Boolean type (I don't know whether the standard requires it or not) then it makes sense to be able to have a 32-bit Boolean, depending on one's needs.
Of course, we'll retain the `Boolean' type (it is standard, and also compatible to any Pascal compiler I know). The point about it is that is has only two values so no confusion can arise about what means True and what means False.
OTOH, any Boolean type with more than two values has such problems. E.g., in C:
typedef int MyBool; /* in Pascal: type MyBool = Integer; */
MyBool a, b; /* var a, b: MyBool; */
[...]
{ a = 1; /* i.e., true */ if (a) /* condition satisfied, as expected */ { ... }
b = 2; /* also "true" */ if (b) /* condition also satisfied */ { ... }
/* Now both a and b are "true", but ... */ if (a == b) /* wrong, oops ... */ { ... } }
This leads to situations where sometimes `!!foo' (i.e., `not not foo') is written to make sure the result is the "canonical" true or false value.
I for one would prefer not to have to change all occurrences of "foo (bar1, bool1, bool2, bool3)" to "foo (bar1, bar2 = 0, bar3 <> 0, bar4 = 0)"
And, assuming one of these booleans is a VAR parameter?
Well, if we really dropped `Boolean', there couldn't be any `Boolean' parameters, anyway. ;-)
But again, that's not the question here. As I said, I don't even plan to drop `WordBool' etc., in spite of the above-mentioned problems. It is only about the `Boolean (n)' syntax.
(BTW, this reminds me of when I recently suggested to remove one of two equivalent switches for the "classic Pascal" mode, and some argued that the CP mode (as a whole) should not be dropped ...)
Frank