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-7-bit Received: by 10.68.191.2 with SMTP id gu2mr13734005pbc.0.1323812933824; Tue, 13 Dec 2011 13:48:53 -0800 (PST) MIME-Version: 1.0 Path: lh20ni19133pbb.0!nntp.google.com!news2.google.com!goblin3!goblin1!goblin.stu.neva.ru!news.tornevall.net!news.jacob-sparre.dk!pnx.dk!jacob-sparre.dk!ada-dk.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Interfaces.Shift_Left Date: Tue, 13 Dec 2011 15:48:47 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <18214312-82f5-45c4-b20d-cb530b500929@h3g2000yqa.googlegroups.com> <5f989095-5c1c-4b23-a538-d70f4718b4b1@l19g2000yqc.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1323812932 8409 69.95.181.76 (13 Dec 2011 21:48:52 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 13 Dec 2011 21:48:52 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Date: 2011-12-13T15:48:47-06:00 List-Id: "awdorrin" wrote in message news:5f989095-5c1c-4b23-a538-d70f4718b4b1@l19g2000yqc.googlegroups.com... > The data being manipulated does start out as signed 32-bit integers - > its the Logical Shift operations in the Interfaces package that are > expecting Unsigned_32 types as input parameters. It does not make sense to "shift" numbers: "shift" is not an operation of a number. It does make sense to "shift" a bunch of bits. Ada allows treating an unsigned number as a "bunch of bits", thus modular types support "and", "or", and shifting. But Ada does not allow that for signed numbers. C programmers sometimes use shifting as a shortcut for multiplying or dividing by a power of 2. But this is premature optimization: any remotely decent compiler will do this automatically, without confusing the reader of the code. (Ever Ada compiler that I've examined the output of does this optimization.) (And this has the advantage of still getting overflow checks for multiplies, so there is a protection against getting the wrong answers by accident.) So, if the data is *really* numeric in nature, then the first choice is to write the operations in terms of multiply and divide. OTOH, if the data is not numeric, then the shifting probably is just used to pack data into a word. That's better done in Ada using representation clauses -- but in the interests of getting your program converted fast, you probably should leave well-enough alone and stick with the shifts. But in that case, the data type should be unsigned (there is no "number" involved). Anyway, I understand if you want to use Unchecked_Conversion as a quick-and-dirty hack -- those are often necessary in the real world. But you shouldn't think of that as the final solution; there is something fundementally wrong with needing to shift signed values, and it would be best to work out what the problem is an eliminate it. Randy.