comp.lang.ada
 help / color / mirror / Atom feed
From: Erik Sigra <sigra@home.se>
Subject: Read booleans from streams
Date: Mon, 25 Mar 2002 00:18:35 +0100
Date: 2002-03-25T00:18:35+01:00	[thread overview]
Message-ID: <mailman.1017011702.18089.comp.lang.ada@ada.eu.org> (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.



             reply	other threads:[~2002-03-24 23:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-24 23:18 Erik Sigra [this message]
2002-03-25  3:57 ` Read booleans from streams 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
replies disabled

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