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-26 09:55:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!tor-nx1.netcom.ca!news1.tor.metronet.ca!nnrp1.tor.metronet.ca!not-for-mail Message-ID: <3CA0B5C4.2060804@home.com> From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Another problem with stream reading. References: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 26 Mar 2002 17:54:12 GMT NNTP-Posting-Host: 198.96.47.195 NNTP-Posting-Date: Tue, 26 Mar 2002 10:54:12 MDT Organization: MetroNet Communications Group Inc. Xref: archiver1.google.com comp.lang.ada:21689 Date: 2002-03-26T17:54:12+00:00 List-Id: Just shooting from the hip here, I think the problem is that you gave the compiler an impossible assignment. By that, I mean that you've declared type Byte to have integer range 0..255 and at the same time said its size has to be 8 bits. There is no room for that range and a sign bit (since it is integer here) to exist in 8 bits (you need 9). As a result of lying to HAL, HAL decided to disregard your statement "for Byte'Size use 8" and used 16 instead. If you want signed numbers, you need to fix the range. If you want unsigned numbers, then you need a modulo type. Erik Sigra wrote: > Now I have the program > > with Ada; use Ada; > with Text_IO; use Text_IO; > with Ada.Streams; use Streams; > with Ada.Streams.Stream_IO; use Stream_IO; > > 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; > > > The data file contains > "����" (hexadecimal "ff fe fd fc") (decimal "255 254 253 252). The output of > the program is: > Read B = 255 > Read B = 253 > > > The problem is that it reads 2 bytes instead of 1 and thus skips each second > byte. Why? > -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg