From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: integers of 1, 2, 4 bytes
Date: Mon, 16 Jun 2014 00:55:58 +0300
Date: 2014-06-16T00:55:58+03:00 [thread overview]
Message-ID: <c06j3eFddf4U1@mid.individual.net> (raw)
In-Reply-To: <c06hlhFd4h9U1@mid.individual.net>
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
. @ .
next prev parent reply other threads:[~2014-06-15 21:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-15 17:57 integers of 1, 2, 4 bytes hreba
2014-06-15 18:43 ` Dmitry A. Kazakov
2014-06-15 20:52 ` hreba
2014-06-15 19:07 ` Niklas Holsti
2014-06-15 21:25 ` hreba
2014-06-15 22:39 ` Georg Bauhaus
2014-06-16 13:37 ` AdaMagica
2014-06-16 4:46 ` J-P. Rosen
2014-06-15 19:26 ` Stefan.Lucks
2014-06-15 21:31 ` hreba
2014-06-15 21:55 ` Niklas Holsti [this message]
2014-06-15 22:09 ` Jeffrey Carter
2014-06-16 15:38 ` Adam Beneschan
2014-06-16 17:27 ` gautier_niouzes
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox