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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: surprise data from Ada.Sequential_IO Date: Mon, 22 Mar 2021 18:40:36 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 22 Mar 2021 17:40:37 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="b53df4a440428053084cdf916ac37f08"; logging-data="18103"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+5vnuoNSdRvnZjVh6XkA79s6KBXNJWfKM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 Cancel-Lock: sha1:bDtAf/R8i6UGbTGrZyyx2A5iHZ8= In-Reply-To: Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:61630 List-Id: On 3/22/21 6:13 PM, John Perry wrote: > Hello all > > 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; This is asking for trouble, > > However, this: > >>> P3.Open(Append_File); P3.Write; P3.Close; > > ...wrote a few bytes of junk between T2's data and T3's data. which you got. When you open a P3.File_Type with mode Append_File, it expects the file to contain an integral number of values of T3 already. What happens if it doesn't appears to be undefined. Either create a record with components of the the three types, instantiate Sequential_IO for that, and write all three values at once, or use streams for heterogeneous I/O. -- Jeff Carter "One day he told me he was a gynecologist. He couldn't speak no foreign languages." Take the Money and Run 147