comp.lang.ada
 help / color / mirror / Atom feed
* integers of 1, 2, 4 bytes
@ 2014-06-15 17:57 hreba
  2014-06-15 18:43 ` Dmitry A. Kazakov
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: hreba @ 2014-06-15 17:57 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-06-16 17:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2014-06-15 22:09 ` Jeffrey Carter
2014-06-16 15:38 ` Adam Beneschan
2014-06-16 17:27 ` gautier_niouzes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox