firth@sei.cmu.edu.UUCP (04/07/87)
Just to correct a couple of minor errors in
a previous post
If somebody constrains a Boolean subtype
to one value, then the following holds
. assignments must be checked (but the check
is against a single value)
. AND and OR need not be checked, assuming the
operands are OK
. NOT and XOR will always raise CONSTRAINT_ERROR
Procedure parameters are passed by value, so the
rules for assignment hold.
If the variable is an array of constrained Boolean
component subtype (phew!) then a component by
component check is needed in principle only on
assignment of an arbitrary value. It is not
needed when the RHS is an expression involving
only similarly constrained array values. On many
machines, these checks can be subsumed under a
block test for (all-zeros) or (all-ones), which
are the only legal aggregate values (assuming
the array is packed).
If the compiler cannot tell whether the Boolean
is constrained, then the proper discriminating
test is indeed "IF subtype'FIRST /= subtype'LAST".
Again, on some machines it might be prudent for
the compiler to compute the value of that expression
at the point where the subtype is declared.eric@burdvax.UUCP (04/18/87)
in article <880@aw.sei.cmu.edu.sei.cmu.edu>, (Robert Firth) says: > > If somebody constrains a Boolean subtype > to one value, then the following holds > > ... > > . NOT and XOR will always raise CONSTRAINT_ERROR > The elaboration of 'a' below will not raise CONSTRAINT_ERROR. subtype bool is boolean range true..true; a : bool := true xor false;
eric@burdvax.PRC.Unisys.COM (Eric Marshall) (04/18/87)
last night I wrote: > > The elaboration of 'a' below will not raise CONSTRAINT_ERROR. > > subtype bool is boolean range true..true; > a : bool := true xor false; This is a poor example, although my point is correct, XOR will not always raise CONSTRAINT_ERROR. Below is a more appropriate example: subtype bool is boolean range false..false; a, b : bool := false; c : bool := a xor b;
firth@sei.cmu.edu (Robert Firth) (04/20/87)
In article <3283@burdvax.PRC.Unisys.COM> eric@burdvax.PRC.Unisys.COM (Eric Marshall) writes: >last night I wrote: >> >> The elaboration of 'a' below will not raise CONSTRAINT_ERROR. >> >> subtype bool is boolean range true..true; >> a : bool := true xor false; > > This is a poor example, although my point is correct, XOR >will not always raise CONSTRAINT_ERROR. Below is a more appropriate >example: > > subtype bool is boolean range false..false; > a, b : bool := false; > c : bool := a xor b; You're right, Eric, and I made a rather stupid error. The original discussion was about a Boolean subtype constrained to one value. Indeed, XOR works iff that one value is FALSE, since FALSE xor FALSE yields FALSE. In the case of XOR between arrays, the code then becomes something like if BOOLEAN_SUBTYPE'FIRST = TRUE then raise CONSTRAINT_ERROR; else null; -- never any need actually to DO the assignment! end if; (I hope)