comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: surprise data from Ada.Sequential_IO
Date: Mon, 22 Mar 2021 18:40:36 +0100	[thread overview]
Message-ID: <s3akql$hln$1@dont-email.me> (raw)
In-Reply-To: <e5df978e-35b6-4224-9028-3cf88bd19872n@googlegroups.com>

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

  reply	other threads:[~2021-03-22 17:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 17:13 surprise data from Ada.Sequential_IO John Perry
2021-03-22 17:40 ` Jeffrey R. Carter [this message]
2021-03-22 18:14   ` John Perry
2021-03-22 19:41     ` Jeffrey R. Carter
2021-03-22 20:54       ` Niklas Holsti
2021-03-23  9:18         ` Jeffrey R. Carter
2021-03-22 21:25       ` Shark8
2021-03-22 17:48 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox