comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Integer'Size < 32 ?
Date: 1996/08/10
Date: 1996-08-10T00:00:00+00:00	[thread overview]
Message-ID: <dewar.839652897@schonberg> (raw)
In-Reply-To: 9608081258.AA02749@most


Wes asks

"   .... range -(2**31) .. ((2**31)-1)

I once used a compiler for which Integer'Size = 32 and which had an
interesting "feature."  It recognized that the above would fit in 32 bits,
so it compiled for that size.  Then at run-time, it would (obeying
the precedence rules) try to compute 2**31 and raise constraint_error.
(I didn't use the parentheses, but that doesn't change the semantics.)
The ugly work-around was

   .... range  -2**31 .. 2**30 + (2**30 - 1);

My question is, "Is this a common 'feature'?"  (Since so many people have
quoted the same example, I presume the answer is 'no')"



First of all let's talk Ada 83. In Ada 83:

   type x is range -(2**31) .. ((2**31)-1);

must work (if there is a suitable base type), and cannot raise
constraint error. However

   subtype y is x range -(2**31) .. ((2**31)-1);

is allowed to raise constraint error, although not required to, and notably
the DEC compiler *did* raise constraint error, although most other compilers
did not.

This was a well known source of undesirable non-portability, and so in
Ada 95, the rules about static expressions were modified to require that
all intermediate static expressions be computed without overflow, so the
above subtype declaration CANNOT cause constraint error in Ada 95.





  parent reply	other threads:[~1996-08-10  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-08  0:00 Integer'Size < 32 ? W. Wesley Groleau (Wes)
1996-08-09  0:00 ` Robert A Duff
1996-08-10  0:00 ` Robert Dewar [this message]
1996-08-11  0:00 ` Mark A Biggar
1996-08-12  0:00   ` Robert Dewar
replies disabled

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