comp.lang.ada
 help / color / mirror / Atom feed
* Size of 0..255 is not 8 bits?
@ 1998-05-14  0:00 Markus Kuhn
  1998-05-13  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Kuhn @ 1998-05-14  0:00 UTC (permalink / 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/>




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

end of thread, other threads:[~1998-05-17  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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     ` 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
1998-05-14  0:00   ` Tom Moran
1998-05-14  0:00   ` Robert Dewar

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