comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: How to write "Hello" to a text file without a line terminator
Date: Fri, 12 Aug 2016 10:34:16 -0700
Date: 2016-08-12T10:34:16-07:00	[thread overview]
Message-ID: <nol1ao$fpp$1@dont-email.me> (raw)
In-Reply-To: <4c49991e-9001-464f-afbb-3fcbf78e5656@googlegroups.com>

On 08/12/2016 12:44 AM, Jerry wrote:
> 
> Both of these programs put a line terminator after Hello.
> 
> with Ada.Text_IO; use Ada.Text_IO;
> procedure test_ada_eol is
> begin
> Put("Hello");
> end test_ada_eol;
> 
> 
> with Ada.Text_IO; use Ada.Text_IO;
> procedure test_ada_eol_to_file is
>    Test_Ada_EOL_File : Ada.Text_IO.File_Type;
> begin
>    Create(Test_Ada_EOL_File, Out_File, "Test Ada EOL.txt");    
>    Put(Test_Ada_EOL_File, "Hello");
>    Close(Test_Ada_EOL_File);
> end test_ada_eol_to_file;

As Wright has pointed out, Close is defined to add a line terminator if the file
does not end with one. This explains the EOL for Test_Ada_Eol_To_File. In
Test_Ada_Eol, you have no call to Close. However, you'll note that File_Type is
defined as needing finalization [ARM A.10.1(86/2)]. While the effect of this
finalization is not defined, it's common to use it to close an open file. Every
Ada compiler I've used has done so. So this is probably the source of the EOL in
Test_Ada_Eol.

To obtain a file without a final EOL, you can use streams, as suggested, or
instantiate Ada.Sequential_IO for Character, which will require that you output
your Characters individually.

However, I don't know any portable way to write to standard output without
adding an EOL. Any output involving Ada.Text_IO.Standard_Output will invoke
Close when the file is finalized.

-- 
Jeff Carter
"Sons of a silly person."
Monty Python & the Holy Grail
02

  reply	other threads:[~2016-08-12 17:34 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-12  4:05 How to write "Hello" to a text file without a line terminator Jerry
2016-08-12  6:41 ` G.B.
2016-08-12  7:23 ` Dmitry A. Kazakov
2016-08-12  7:41   ` J-P. Rosen
2016-08-12  7:46     ` Jerry
2016-08-12  7:44   ` Jerry
2016-08-12 17:34     ` Jeffrey R. Carter [this message]
2016-08-13  3:21       ` Jerry
2016-08-13  4:23         ` Jeffrey R. Carter
2016-08-13  9:12           ` AdaMagica
2016-08-13 18:03             ` Jeffrey R. Carter
2016-08-14  7:58               ` AdaMagica
2016-08-14  8:30                 ` Simon Wright
2016-08-14  8:54                   ` Dmitry A. Kazakov
2016-08-14  9:40                     ` Simon Wright
2016-08-14 10:17                       ` Dmitry A. Kazakov
2016-08-14 11:28                         ` Simon Wright
2016-08-14 13:31                           ` Dmitry A. Kazakov
2016-08-15 23:35                       ` Randy Brukardt
2016-08-14 13:28                   ` AdaMagica
2016-08-14 13:54                     ` Simon Wright
2016-08-14 17:05                     ` Jeffrey R. Carter
2016-08-14 18:26                       ` AdaMagica
2016-08-14 19:19                         ` Dmitry A. Kazakov
2016-08-14 13:32                   ` AdaMagica
2016-08-14 16:39                   ` Jeffrey R. Carter
2016-08-12  7:46   ` Simon Wright
     [not found]   ` <noka54$ci$1@dont-email.me>
2016-08-12 13:44     ` 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