From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,ba0587ecc5989bed X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-25 14:35:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Another problem with stream reading. Date: 25 Mar 2002 17:28:55 -0500 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: skates.gsfc.nasa.gov 1017095667 24446 128.183.220.71 (25 Mar 2002 22:34:27 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 25 Mar 2002 22:34:27 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:21657 Date: 2002-03-25T22:34:27+00:00 List-Id: Erik Sigra writes: > m�ndagen den 25 mars 2002 20.01 skrev du: > > Erik Sigra 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