From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
Subject: Size of 0..255 is not 8 bits?
Date: 1998/05/14
Date: 1998-05-14T00:00:00+00:00 [thread overview]
Message-ID: <355A436E.11F76529@cl.cam.ac.uk> (raw)
Gnat-3.10p on Linux reads 2 bytes from a stream for an object of
type range 0..255 that was forced with a 'Size representation clause
to be 8 bits long.
Example:
-----------------------------------------------------------------
with Ada.Text_IO.Text_Streams, Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO.Text_Streams, Ada.Text_IO, Ada.Integer_Text_IO;
procedure Strange2 is
type Value is range 0..255;
for Value'Size use 8;
V: Value;
begin
for X in 1..5 loop
Value'Read(Stream(Standard_Input), V);
Put(Integer(V));
New_Line;
end loop;
end Strange2;
-----------------------------------------------------------------
$ echo ABCDEFGHIJKLMNOP | ./strange2
65
67
69
71
73
Did I missunderstand something and is S'Size not usable for enforcing
the number of bits allocated for a type?
Is 0..255 a type for signed 16-bit arithmetic and not a type for
(as I had naturally assumed) 8-bit unsigned arithmetic?
Do I have to use Unsigned_8 instead if I want to have a guarantee
to get an 8-bit word (which doesn't provide arithmetic overflow
checks)?
Markus
--
Markus G. Kuhn, Security Group, Computer Lab, Cambridge University, UK
email: mkuhn at acm.org, home page: <http://www.cl.cam.ac.uk/~mgk25/>
next reply other threads:[~1998-05-14 0:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-05-14 0:00 Markus Kuhn [this message]
1998-05-13 0:00 ` Size of 0..255 is not 8 bits? Matthew Heaney
1998-05-14 0:00 ` Tom Moran
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Markus Kuhn
1998-05-14 0:00 ` John McCabe
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Simon Pilgrim
1998-05-15 0:00 ` Markus Kuhn
1998-05-15 0:00 ` Samuel T. Harris
1998-05-15 0:00 ` Tucker Taft
1998-05-15 0:00 ` Joe Gwinn
1998-05-16 0:00 ` Robert Dewar
1998-05-17 0:00 ` Joe Gwinn
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox