comp.lang.ada
 help / color / mirror / Atom feed
From: hreba <hreba@terra.com.br>
Subject: integers of 1, 2, 4 bytes
Date: Sun, 15 Jun 2014 14:57:31 -0300
Date: 2014-06-15T14:57:31-03:00	[thread overview]
Message-ID: <c0654eFaetvU1@mid.individual.net> (raw)

Hi,

I want to translate some of my Oberon programs to Ada.

So I need the Oberon types SHORTINT (1 byte), INTEGER (2 bytes) and 
LONGINT (4 bytes). A type BYTE (1 byte, values 0..255) would be useful 
too. In Oberon one uses CHAR for that.

The most obvious translation for INTEGER would be

   type INT is range -32768 .. 32767;

(all platforms I have been working on use the two's complement).

My Ada book says that range checks are applied to constrained subtypes 
(like that one) but not to unconstrained subtypes, but but overflow 
checks are applied nevertheless. So I came up with

   type Int16 is range -32768 .. 32767;
   for Int16'Size use 16;
   type INT is new Int16'Base;

as a more efficient definition.

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?

And how about non-negative types? Would the following have the values
0 .. 255?

   type Nat8 is range 0..1;
   for Nat8'Size use 8;
   type BYTE is new Nat8'Base;
-- 
Frank Hrebabetzky		+55 / 48 / 3235 1106
Florianopolis, Brazil

             reply	other threads:[~2014-06-15 17:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-15 17:57 hreba [this message]
2014-06-15 18:43 ` integers of 1, 2, 4 bytes 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
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