From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!weretis.net!feeder8.news.weretis.net!npeer.as286.net!npeer-ng0.as286.net!proxad.net!feeder1-1.proxad.net!cleanfeed1-a.proxad.net!nnrp1-1.free.fr!not-for-mail Date: Sat, 15 Jan 2022 11:36:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US Newsgroups: comp.lang.ada References: <61e1c144$0$6478$426a74cc@news.free.fr> From: DrPi <314@drpi.fr> Subject: Re: Usage of Stream Set_Index() function In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <61e2a3a0$0$8882$426a34cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 15 Jan 2022 11:36:16 CET NNTP-Posting-Host: 82.65.30.55 X-Trace: 1642242976 news-4.free.fr 8882 82.65.30.55:58715 X-Complaints-To: abuse@proxad.net Xref: reader02.eternal-september.org comp.lang.ada:63378 List-Id: Le 14/01/2022 à 21:35, Niklas Holsti a écrit : > On 2022-01-14 20:30, DrPi wrote: >> >> Hi, >> >> I'm writing an application where I read a file with a complex structure. >> For this, I use Ada.Streams.Stream_IO package. >> To read the file, I need to position the file pointer to the correct >> location. I do this using Set_Index(). >> >> In ARM A.12.1, it is stated : >> For Read and Write with a Positive_Count parameter, the value of the >> current index is set to the value of the Positive_Count parameter plus >> the number of stream elements read or written. >> >> I don't understand the "plus the number of stream elements read or >> written". > > > For Write, the ARM also says: "The Write procedure with a Positive_Count > parameter starts writing at the specified index". And then, after the > data have been written, naturally the current index of the stream has > been increased, to point at the position after the written data. That is > the meaning of the "plus" phrase. > > And Read analogously. The "plus" phrase explains what the value of the > current index is _after_ the Read or Write. But both the Read and the > Write _start_ reading/writing at the index given in the From/To parameters. > > >> Does this mean one can't go back to beginning of file once data have >> been read ? > > > No, Set_Index can do that, whether the last action was writing or > reading. And the Write/Read with an index parameter can also do that. > > But if you have set the current index to the desired position with > Set_Index, you don't need to use the Read/Write that have a > Positive_Count (index) parameter. > > This code: > >    Set_Index (F, I); >    Write (F, Item); > > is equivalent to: > >    Write (F, Item, I); > > and ditto Read. Ok, so Set_Index() works as expected. Nothing special. Reading the LRM made me understand things incorrectly because of the way it is written. It is written : 32 The Set_Index procedure sets the current index to the specified value. Then, it is written : 32.1/1 ... 32.2/1 ... ... Reading this, I thought 32.1/1, 32.2/1 etc lines apply to 32 (Set_Index() function). So, I was completely lost to understand the meaning of these lines.