From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: DECAda/VMS - calling GETJPI
Date: 1996/06/03
Date: 1996-06-03T00:00:00+00:00 [thread overview]
Message-ID: <dewar.833818928@schonberg> (raw)
In-Reply-To: 4ouuuv$6hd@linus.mitre.org
Micheal Brenner said:
"you could just assign it:
integer_minus_1: integer := -1;
x: unsigned_longword := unsigned_longword (integer_minus_1);
because Ada 95 modular types truncate numbers to their modular range
without giving a constraint_error."
That's quite wrong, the type conversoin checks that the value is in
range, and the value is outside the range. Indeed if you add a constant
to the declaration of integer_minus_1, the out of range condition will
be detected at compile time by GNAT:
1. procedure z is
2. type ul is mod 2 ** 64;
3. integer_minus_1: constant integer := -1;
4. x: ul := ul (integer_minus_1);
|
>>> warning: static value out of range of type "ul" defined at line 2
>>> warning: "constraint_error" will be raised at runtime
5. begin
6. null;
7. end;
Yes, you can apply the unary minus operator to an unsigned vaue and get
modular results as expected, but here the minus is applied to a signed
type and generates a real minus one, which is definitely outside the
range of any unsigned type.
It's probably time again to repost the plea that if you suggest a solution
to a problem, compile an example and make sure it works. No one is realiable
enough to be 100% accurate without such a backup check, and posting incorrect
information on Ada can cause a lot of confusion!
IN fact the proper solution in this case is trivial:
procedure z is
type unsigned_longword is mod 2 ** 64;
x: unsigned_longword := -1;
begin
null;
end;
or, if you want the constant integer_minus_1, define it as type ul to start
with.
next prev parent reply other threads:[~1996-06-03 0:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-06-03 0:00 DECAda/VMS - calling GETJPI Alan Paterson
1996-06-03 0:00 ` Ken Garlington
1996-06-03 0:00 ` Mats Weber
1996-06-03 0:00 ` Stuart Palin
1996-06-03 0:00 ` Michael F Brenner
1996-06-03 0:00 ` Robert Dewar [this message]
1996-06-04 0:00 ` Michael F Brenner
1996-06-04 0:00 ` Robert Dewar
1996-06-04 0:00 ` Michael F Brenner
1996-06-04 0:00 ` Robert Dewar
1996-06-04 0:00 ` Robert Dewar
1996-06-05 0:00 ` Wraparound on modular conversion (was: DECAda/VMS - calling GETJPI) Tucker Taft
1996-06-05 0:00 ` Robert Dewar
1996-06-05 0:00 ` DECAda/VMS - calling GETJPI Fergus Henderson
1996-06-05 0:00 ` Robert A Duff
1996-06-05 0:00 ` Robert A Duff
1996-06-05 0:00 ` Robert Dewar
1996-06-05 0:00 ` Adam Beneschan
1996-06-07 0:00 ` Norman H. Cohen
1996-06-11 0:00 ` Adam Beneschan
1996-06-04 0:00 ` Ken Garlington
1996-06-06 0:00 ` Robert Dewar
-- strict thread matches above, loose matches on Subject: below --
1996-06-06 0:00 George Haddad
1996-06-07 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