From: Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk>
Subject: Re: Size of 0..255 is not 8 bits?
Date: 1998/05/15
Date: 1998-05-15T00:00:00+00:00 [thread overview]
Message-ID: <355C19C8.5D3A4545@cl.cam.ac.uk> (raw)
In-Reply-To: dewar.895191407@merv
Robert Dewar wrote:
> It is indeed a bug in a compiler if a Size clause for an object does not
> result in the object tkaing the indicated nnumber of bits. But perhaps
> you had better post the EXACT code that leads you to that conclusion.
Ok, here comes the exact code and the execution result of what
confuses me.
Environment: gnat-3.10p-i386-linux-bin
Linux kernel 2.0.29
libc.so.5.3.12.
---------------------------------------------------------------------
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;
for V'Size use 8;
begin
for X in 1..5 loop
Value'Read(Stream(Standard_Input), V);
Put(Integer(V));
New_Line;
end loop;
end Strange2;
---------------------------------------------------------------------
$ echo "ABCDEFGHIJK" | ./strange2
65
67
69
71
73
---------------------------------------------------------------------
PROBLEM: Although I have been very explicit about that I want V
to be 8 bits large, and although GNAT generated no errors or
warnings when compiling the above, Value'Read clearly eats 16-bit
chunks per call, but stores only the first 8 bits, which I consider
highly surprising.
I would have expected to see either an output like
65
66
67
68
69
or to get a compiler error message telling me that the "use 8"
representation clause for "range 0..255" cannot be used.
---------------------------------------------------------------------
And here is a related problem if I use streams on range 0..255
Arrays:
---------------------------------------------------------------------
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 Strange3 is
type Value is range 0..255;
for Value'Size use 8;
type Value_Array is array(1..5) of Value;
for Value_Array'Component_Size use 8;
pragma Pack(Value_Array);
VA: Value_Array;
begin
Put(Value_Array'Size);
Value_Array'Read(Stream(Standard_Input), VA);
Put_Line("Read Success");
for X in 1..5 loop
Put(Integer(VA(X)));
New_Line;
end loop;
end Strange3;
---------------------------------------------------------------------
$ echo "ABCDEFGHIJK" | ./strange2
40
raised CONSTRAINT_ERROR
---------------------------------------------------------------------
PROBLEM: Why do I get a CONSTRAINT_ERROR here?
---------------------------------------------------------------------
This looks like a GNAT 3.10p bug to me. If I replace "range 0..255"
with "mod 256", then everything works nicely.
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 prev parent reply other threads:[~1998-05-15 0:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-05-14 0:00 Size of 0..255 is not 8 bits? Markus Kuhn
1998-05-13 0:00 ` Matthew Heaney
1998-05-14 0:00 ` Markus Kuhn
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Simon Pilgrim
1998-05-15 0:00 ` Joe Gwinn
1998-05-16 0:00 ` Robert Dewar
1998-05-17 0:00 ` Joe Gwinn
1998-05-15 0:00 ` Markus Kuhn [this message]
1998-05-15 0:00 ` Samuel T. Harris
1998-05-15 0:00 ` Tucker Taft
1998-05-14 0:00 ` John McCabe
1998-05-14 0:00 ` Robert Dewar
1998-05-14 0:00 ` Tom Moran
1998-05-14 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox