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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: integers of 1, 2, 4 bytes Date: Mon, 16 Jun 2014 00:55:58 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: individual.net rdyIhaz3k0vhCow9joODzwMlPEn8M8NYdQC3C3h1DhW1r+fQ85 Cancel-Lock: sha1:i/aqZ7dmlJ+HUkVw67IGFabIO8Y= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:20336 Date: 2014-06-16T00:55:58+03:00 List-Id: On 14-06-16 00:31 , hreba wrote: > On 06/15/2014 04:26 PM, Stefan.Lucks@uni-weimar.de wrote: >> On Sun, 15 Jun 2014, hreba wrote: [snip] >>> Now it seems the range specification doesn't matter any more and that >>> I could equally write >>> >>> type Int16 is range -1 .. 1; >>> for Int16'Size use 16; >>> type INT is new Int16'Base; >>> >>> Would you really define a 16 bit integer type this way? >> >> Firstly, this makes your program hard to read, so this is poor software >> engineering. Secondly, it does not do what you want it to do -- i.e., it >> does not omit the range checks. And finally, the Ada compiler has a >> great deal of freedom what Int16'Base actually is. While I find it hard >> to imagine that an Ada compiler for any target machine with 2-complement >> arithmetic would not set Int16'Base to the range -2**15 .. +2**15-1, the >> Ada compiler might still surprise you. I tried this on Mac OS-X, x86_64, GNAT 4.5: with Ada.Text_IO; use Ada.Text_IO; procedure Bases is type Int16 is range -1 .. 1; for Int16'Size use 16; type INT is new Int16'Base; begin Put_Line (INT'Image (INT'First) & " .. " & INT'Image (INT'Last)); end Bases; The result is: -128 .. 127 -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .