From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c5f68ab74d5099ee X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.212.232 with SMTP id nn8mr11074955pbc.1.1323740188173; Mon, 12 Dec 2011 17:36:28 -0800 (PST) Path: lh20ni15997pbb.0!nntp.google.com!news1.google.com!postnews.google.com!p14g2000yqp.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Interfaces.Shift_Left Date: Mon, 12 Dec 2011 17:36:27 -0800 (PST) Organization: http://groups.google.com Message-ID: <78d3cdfc-2b37-4178-b116-8803488405e6@p14g2000yqp.googlegroups.com> References: <18214312-82f5-45c4-b20d-cb530b500929@h3g2000yqa.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1323740188 31108 127.0.0.1 (13 Dec 2011 01:36:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 Dec 2011 01:36:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p14g2000yqp.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-12-12T17:36:27-08:00 List-Id: On Dec 12, 3:34=A0pm, Simon Wright wrote: > awdorrin writes: > > Cur_Word :=3D (Cur_Word OR Shift_Left( Unsigned_32(Data), > > Bits_To_Shift)); > > INT_PTR.all :=3D 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