From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: surprise data from Ada.Sequential_IO Date: Mon, 22 Mar 2021 18:48:42 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:61632 List-Id: On 2021-03-22 18:13, John Perry wrote: > I was using gnat 2020 CE on a Linux machine the other day, and wanted to write out data for three different types T1, T2, T3 to a file. I instantiated a Sequential_IO package for each; call them P1, P2, P3. > > The following worked as expected (sorry for the abbreviations but I think it will be clear): > >>> P1.Create; P1.Write; P1.Close; P2.Open(Append_File); P2.Write; P2.Close; > > However, this: > >>> P3.Open(Append_File); P3.Write; P3.Close; > > ...wrote a few bytes of junk between T2's data and T3's data. > > I used a hex editor to check the output file between writes, and there was no junk after P2.Close nor after P3.Open; it always came at the beginning of P3.Write. > > I reworked the type definitions so that T3's data was included at the end of T2, and in this case P2.Write wrote the data properly, as desired. However, this is not the sort of permanent solution I'd want. > > Has anyone else encountered this? Could this be due to alignment issues? Is there some way to avoid this without putting the data there? I did not use Sequential_IO for decades. I doubt it was ever intended for the misuse you invented. For practical point of view, I would consider this package obsolete, superseded by Ada.Streams.Stream_IO. It is exactly meant for your case, especially if you override the attributes of T1, T2, T3 (to make it portable). And you are in full control of what is going on, e.g. no stuff like vertical formats and stupid EOF sequences. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de