Saturday, April 28, 2012

8.3


(a) The Boolean data type may or may not have an order relation (pg332), and it may or may not be convertible to integral types (pg350), depending on the language. Compare the treatment of the Boolean type in at least two of the following languages with regards to these two issues: Java, C++, Ada, ML.

In Java, boolean is a primitive data type.
In Ada, the boolean type is an enumeration type.In C++, the boolean type is a Numeric type. In Java and C++, 0 represents false, while all positive nonzero values evaluate to true. The boolean can be used before or after an operator. Booleans can be cast as integers in both languages, and when doing so, false => 0 and true => 1

(b) Is it useful for booleans to be ordered? convertible to integers?
If booleans were not ordered, they might not be consistently convertible to integers. It is useful to convert booleans to integers for use of booleans in calculations more concisely

No comments:

Post a Comment