From: Adam Beneschan <adam@irvine.com>
Subject: Re: Interfaces.Shift_Left
Date: Mon, 12 Dec 2011 17:36:27 -0800 (PST)
Date: 2011-12-12T17:36:27-08:00 [thread overview]
Message-ID: <78d3cdfc-2b37-4178-b116-8803488405e6@p14g2000yqp.googlegroups.com> (raw)
In-Reply-To: m2pqft9xfe.fsf@pushface.org
On Dec 12, 3:34 pm, Simon Wright <si...@pushface.org> wrote:
> awdorrin <awdor...@gmail.com> writes:
> > Cur_Word := (Cur_Word OR Shift_Left( Unsigned_32(Data),
> > Bits_To_Shift));
> > INT_PTR.all := Integer_32(Cur_Word);
>
> > I understand that the result from the shift_left is a negative number,
> > so it is being seen by Ada as a large positive number ( > (2^31-1))
> > which is why I'm getting the Constraint error;
>
> > Maybe its my history with C that is confusing me, but shouldn't there
> > be an easy way to cast the value back to a negative Integer_32 from an
> > Unsigned_32?
>
> Ada doesn't have an easy way to do what you ask; one way you can do it
> is by instantiating Ada.Unchecked_Conversion, which is deliberately
> obvious so that reviewers know that they have to take more care than
> usual.
In fact, I think most C casts are, in essence, "unchecked
conversions". In Ada, however, type conversions (specifically, value
conversions) are more strictly defined, and it's defined so that the
result of a type conversion has the same *value* as the operand, with
allowance for rounding. So the idea of a type conversion whose
operand is a positive number and whose result is a negative number is
not how Ada does things.
-- Adam
next prev parent reply other threads:[~2011-12-13 1:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-12 22:30 Interfaces.Shift_Left awdorrin
2011-12-12 23:34 ` Interfaces.Shift_Left Simon Wright
2011-12-13 1:36 ` Adam Beneschan [this message]
2011-12-13 12:00 ` Interfaces.Shift_Left Brian Drummond
2011-12-13 13:15 ` Interfaces.Shift_Left awdorrin
2011-12-13 21:48 ` Interfaces.Shift_Left Randy Brukardt
2011-12-14 18:28 ` Interfaces.Shift_Left awdorrin
2011-12-14 22:49 ` Interfaces.Shift_Left Randy Brukardt
2011-12-15 9:51 ` Interfaces.Shift_Left Niklas Holsti
2011-12-16 0:23 ` Interfaces.Shift_Left Randy Brukardt
2011-12-18 20:47 ` Interfaces.Shift_Left Niklas Holsti
2011-12-20 0:38 ` Interfaces.Shift_Left Randy Brukardt
2011-12-20 2:18 ` Interfaces.Shift_Left Shark8
2011-12-20 10:08 ` Interfaces.Shift_Left Dmitry A. Kazakov
2011-12-20 19:38 ` Interfaces.Shift_Left Niklas Holsti
2011-12-20 20:46 ` Interfaces.Shift_Left Niklas Holsti
2011-12-20 21:13 ` Interfaces.Shift_Left Simon Wright
2011-12-20 21:08 ` Interfaces.Shift_Left Simon Wright
2011-12-20 23:26 ` Interfaces.Shift_Left Randy Brukardt
2011-12-20 23:36 ` Interfaces.Shift_Left Randy Brukardt
2011-12-21 0:44 ` Interfaces.Shift_Left Georg Bauhaus
2011-12-21 7:23 ` Interfaces.Shift_Left AdaMagica
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox