comp.lang.ada
 help / color / mirror / Atom feed
* Read booleans from streams
@ 2002-03-24 23:18 Erik Sigra
  2002-03-25  3:57 ` Eric G. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Sigra @ 2002-03-24 23:18 UTC (permalink / raw)


I tried to read bytes from a stream and interpret each bit as a Boolean. But 
it did not work as expected. It reads 1 byte for each bit. How should I do 
instead?


streamtest.adb
==============
with Ada.Text_IO;           use Ada.Text_IO;
with Ada.Streams;           use Ada.Streams;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;

procedure Streamtest is
   type Boolean_Aggregate is array (0 .. 7) of Boolean;
   for Boolean_Aggregate'Component_Size use 1;

   Current_Byte : Boolean_Aggregate;

   The_File : Stream_IO.File_Type;

   The_Stream : Stream_Access;

begin

   Open (The_File, In_File, "data");

   The_Stream := Stream (The_File);

   loop
      Boolean_Aggregate'Read (The_Stream, Current_Byte);
      for I in Boolean_Aggregate'Range loop
         Put(Current_Byte (I)'Img & ' ');
      end loop;
      New_Line;
   end loop;
end Streamtest;


data
====
02027203


user > ./streamtest
FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE

raised ADA.IO_EXCEPTIONS.END_ERROR : s-stratt.adb:170


I have checked that the size of Boolean_Aggregate is 8 and not 64.



^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <200203242318.g2ONIkc12876@a77.ib.student.liu.se>]

end of thread, other threads:[~2002-03-25 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-24 23:18 Read booleans from streams Erik Sigra
2002-03-25  3:57 ` Eric G. Miller
2002-03-25 11:21   ` Erik Sigra
     [not found]   ` <200203251121.g2PBL9401018@a77.ib.student.liu.se>
2002-03-25 16:00     ` sk
     [not found] <200203242318.g2ONIkc12876@a77.ib.student.liu.se>
2002-03-25  2:05 ` sk
     [not found] ` <3C9E85F6.8EDF3AAD@myob.com>
2002-03-25 10:46   ` Erik Sigra

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