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=-0.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,REPLYTO_WITHOUT_TO_CC autolearn=no 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-27 07:49:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fr.clara.net!heighliner.fr.clara.net!freenix!enst!enst.fr!not-for-mail From: Erik Sigra Newsgroups: comp.lang.ada Subject: Re: Another problem with stream reading. Date: Wed, 27 Mar 2002 16:53:10 +0100 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: <3CA0B5C4.2060804@home.com> Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Trace: avanie.enst.fr 1017244143 20015 137.194.161.2 (27 Mar 2002 15:49:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 27 Mar 2002 15:49:03 +0000 (UTC) Return-Path: X-Mailer: KMail [version 1.3.2] In-Reply-To: <3CA0B5C4.2060804@home.com> Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.8 Precedence: bulk X-Reply-To: sigra@home.se List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:21725 Date: 2002-03-27T16:53:10+01:00 tisdagen den 26 mars 2002 18.54 skrev du: > 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 look carefully at my code you can se that i did NOT write "Integer range", just "range". And there is certainly no need for a sign bit for the range 0 .. 255. If I lie to the compiler, it does certainly not disregard it. It complais loudly. If I for example say "for Byte'Size use 7;", it replies "size for "Byte" too small, minimum allowed is 8" > If you want signed numbers, you need to fix the range. If > you want unsigned numbers, then you need a modulo type. I should not need a modulo type for unsigned numbers. See "Programming in Ada 95" by John Barnes, 2nd edition, page 552: " For example we can specify the amount of storage to be allocated for objects of a type, for the storage pool of an access type and for the working storage of a task type. This is done by an attribute definition clause. Thus type Byte is range 0 .. 255; for Byte'Size use 8; indicates that objects of type Byte should occupy only 8 bits. The size of individual objects can also be specified." > 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?