comp.lang.ada
 help / color / mirror / Atom feed
* Constrained Boolean
@ 1987-04-07 14:14 firth
  1987-04-18  1:46 ` eric
  0 siblings, 1 reply; 4+ messages in thread
From: firth @ 1987-04-07 14:14 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Constrained Boolean
  1987-04-07 14:14 Constrained Boolean firth
@ 1987-04-18  1:46 ` eric
  1987-04-18 12:38   ` Eric Marshall
  0 siblings, 1 reply; 4+ messages in thread
From: eric @ 1987-04-18  1:46 UTC (permalink / raw)


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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Constrained Boolean
  1987-04-18  1:46 ` eric
@ 1987-04-18 12:38   ` Eric Marshall
  1987-04-20 14:01     ` Robert Firth
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Marshall @ 1987-04-18 12:38 UTC (permalink / raw)


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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Constrained Boolean
  1987-04-18 12:38   ` Eric Marshall
@ 1987-04-20 14:01     ` Robert Firth
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Firth @ 1987-04-20 14:01 UTC (permalink / raw)


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)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1987-04-20 14:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1987-04-07 14:14 Constrained Boolean firth
1987-04-18  1:46 ` eric
1987-04-18 12:38   ` Eric Marshall
1987-04-20 14:01     ` Robert Firth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox