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!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Usage of Stream Set_Index() function Date: Fri, 14 Jan 2022 22:35:49 +0200 Organization: Tidorum Ltd Message-ID: References: <61e1c144$0$6478$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Rl8Cg9dU/bJpAmrHwKdGNA/lR+t9Gv5uNsyDdrLN2U5Niv5mBW Cancel-Lock: sha1:jdoJKPENnHlj8H4T/SRymXlUG9Y= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: <61e1c144$0$6478$426a74cc@news.free.fr> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63376 List-Id: 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.