comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Another problem with stream reading.
Date: 25 Mar 2002 17:28:55 -0500
Date: 2002-03-25T22:34:27+00:00	[thread overview]
Message-ID: <uvgbkth7c.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: mailman.1017083461.9710.comp.lang.ada@ada.eu.org

Erik Sigra <sigra@home.se> writes:

> m�ndagen den 25 mars 2002 20.01 skrev du:
> > Erik Sigra <sigra@home.se> wrote in
> >
> > news:mailman.1017082205.9199.comp.lang.ada@ada.eu.org:
> > > procedure Streamtest is
> > >    The_File : Stream_IO.File_Type;
> > > begin
> > >    Open (The_File, In_File, "data");
> > >    declare
> > >       The_Stream : Stream_Access := Stream (The_File);
> > >       type Byte is range 0 .. 255;
> > >       for Byte'Size use 8;
> > >       B : Byte;
> > >    begin
> > >       while not End_Of_File (The_File) loop
> > >          Byte'Read (The_Stream, B);
> > >          Put_Line ("Read B = " & B'Img);
> > >       end loop;
> > >    end;
> > > end Streamtest;
> >
> > Don't know exactly why, but is you modify:
> >
> > type Byte is mod 256;
> >
> > it works properly.
> 
> Yes it works here to, thanks!
> 
> Does anyone know what causes this behaviour? Is it specified or should I 
> report it to the compiler maker?

Stream_IO must read and write the base type of the object. For "type
Byte is range 0 .. 255", the base type is a signed integer, so it
takes 16 bits. for "type Byte is mod 256", the base type is 8 bits.

To see why Stream_IO must read and write the base type, consider:

declare
    A : Byte'base;
begin
    Byte'Write (The_Stream, A);
end;

It gets worse; some compilers choose a 16 bit base type for "type
Signed_Byte is -128 .. 127;", and they are compliant with the Ada
standard. So basically, Stream_IO is _not_ guaranteed to be compatible
between compilers.

-- 
-- Stephe



  parent reply	other threads:[~2002-03-25 22:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-25 18:53 Another problem with stream reading Erik Sigra
2002-03-25 19:01 ` Dan Andreatta
2002-03-25 19:14   ` Erik Sigra
2002-03-25 22:20     ` Jeffrey Carter
2002-03-25 22:28     ` Stephen Leake [this message]
2002-03-26 17:54 ` Warren W. Gay VE3WWG
2002-03-27 15:53   ` Erik Sigra
2002-03-27 21:22     ` Warren W. Gay VE3WWG
2002-03-27 22:50     ` Dan Andreatta
2002-03-27 23:55     ` Randy Brukardt
2002-03-28  0:18       ` David Bolen
2002-03-28 22:30         ` Randy Brukardt
2002-03-28  0:33       ` tmoran
2002-03-28 15:21       ` Marin David Condic
2002-03-29 11:30         ` Larry Kilgallen
2002-03-29 14:33           ` Marin David Condic
replies disabled

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