* What's the cause of extra new line with Text_IO when program exit
@ 2013-08-16 1:02 Zhu, Qun-Ying
2013-08-16 3:17 ` Jeffrey Carter
0 siblings, 1 reply; 5+ messages in thread
From: Zhu, Qun-Ying @ 2013-08-16 1:02 UTC (permalink / raw)
Hi,
I have known this problem for quite some time, but did not really know
why it behave like this.
These two programs:
======================================================================
-- hello.adb
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put("Hello");
Put(" ");
Put("World!");
end Hello;
-- hello_stream.adb
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO.Text_Streams; use Ada.Text_IO.Text_Streams;
procedure hello_stream is
std_out : Stream_Access;
begin
std_out := Stream (Standard_Output);
String'Write (std_out, "Hello");
String'Write (std_out, " ");
String'Write (std_out, "World!");
end hello_stream;
==================================================================
When executing, they have different behavior.
For hello, you have:
# ./hello
Hello World!
#
While for hello_stream, you got:
# ./hello_stream
Hello World!#
If change the last Put to Put_Line for hello, you got the same result.
I would like to know why it is like that.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What's the cause of extra new line with Text_IO when program exit
2013-08-16 1:02 What's the cause of extra new line with Text_IO when program exit Zhu, Qun-Ying
@ 2013-08-16 3:17 ` Jeffrey Carter
2013-08-17 17:54 ` Dennis Lee Bieber
0 siblings, 1 reply; 5+ messages in thread
From: Jeffrey Carter @ 2013-08-16 3:17 UTC (permalink / raw)
On 08/15/2013 06:02 PM, Zhu, Qun-Ying wrote:
>
> When executing, they have different behavior.
>
> For hello, you have:
> # ./hello
> Hello World!
> #
>
> While for hello_stream, you got:
> # ./hello_stream
> Hello World!#
>
> If change the last Put to Put_Line for hello, you got the same result.
> I would like to know why it is like that.
Ada.Text_IO writes to a text file of type Ada.Text_IO.File_Type; Hello writes to
the file Standard_Output. Text files consist of lines of text; lines are
conceptually terminated by a line terminator. For a version of Unix such as you
seem to be using, the conceptual terminator is an actual LF character.
While it is not defined by the language what happens to a File_Type when the
program ends [ARM A.7(6)], it does require that File_Type have finalization [ARM
A.10.1(86)]. A logical thing for this finalization to do is to make sure that
the last line is terminated, and it appears that your implementation does this.
A stream is a different creature than a text file, and doesn't know about lines
or terminators, so it should not be surprising that it adds no terminator.
--
Jeff Carter
"It is the German who is so uncourteous to his verbs."
A Scandal in Bohemia
122
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What's the cause of extra new line with Text_IO when program exit
2013-08-16 3:17 ` Jeffrey Carter
@ 2013-08-17 17:54 ` Dennis Lee Bieber
2013-08-17 21:54 ` Jeffrey Carter
2013-08-19 21:58 ` Randy Brukardt
0 siblings, 2 replies; 5+ messages in thread
From: Dennis Lee Bieber @ 2013-08-17 17:54 UTC (permalink / raw)
On Thu, 15 Aug 2013 20:17:46 -0700, Jeffrey Carter
<spam.jrcarter.not@spam.not.acm.org> declaimed the following:
>While it is not defined by the language what happens to a File_Type when the
>program ends [ARM A.7(6)], it does require that File_Type have finalization [ARM
>A.10.1(86)]. A logical thing for this finalization to do is to make sure that
>the last line is terminated, and it appears that your implementation does this.
>
Heck, isn't there some mention of also having an EOF marker written?
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What's the cause of extra new line with Text_IO when program exit
2013-08-17 17:54 ` Dennis Lee Bieber
@ 2013-08-17 21:54 ` Jeffrey Carter
2013-08-19 21:58 ` Randy Brukardt
1 sibling, 0 replies; 5+ messages in thread
From: Jeffrey Carter @ 2013-08-17 21:54 UTC (permalink / raw)
On 08/17/2013 10:54 AM, Dennis Lee Bieber wrote:
> On Thu, 15 Aug 2013 20:17:46 -0700, Jeffrey Carter
> <spam.jrcarter.not@spam.not.acm.org> declaimed the following:
>
>> While it is not defined by the language what happens to a File_Type when the
>> program ends [ARM A.7(6)], it does require that File_Type have finalization [ARM
>> A.10.1(86)]. A logical thing for this finalization to do is to make sure that
>> the last line is terminated, and it appears that your implementation does this.
>>
> Heck, isn't there some mention of also having an EOF marker written?
When you close a file, yes. It may not make sense to close standard output.
--
Jeff Carter
"This scene's supposed to be in a saloon, but
the censor cut it out. It'll play just as well
this way." [in a soda fountain]
Never Give a Sucker an Even Break
113
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What's the cause of extra new line with Text_IO when program exit
2013-08-17 17:54 ` Dennis Lee Bieber
2013-08-17 21:54 ` Jeffrey Carter
@ 2013-08-19 21:58 ` Randy Brukardt
1 sibling, 0 replies; 5+ messages in thread
From: Randy Brukardt @ 2013-08-19 21:58 UTC (permalink / raw)
"Dennis Lee Bieber" <wlfraed@ix.netcom.com> wrote in message
news:c5ev09h1d6ffg0bbgtqebl4fjt5d567bco@4ax.com...
> On Thu, 15 Aug 2013 20:17:46 -0700, Jeffrey Carter
> <spam.jrcarter.not@spam.not.acm.org> declaimed the following:
>
>>While it is not defined by the language what happens to a File_Type when
>>the
>>program ends [ARM A.7(6)], it does require that File_Type have
>>finalization [ARM
>>A.10.1(86)]. A logical thing for this finalization to do is to make sure
>>that
>>the last line is terminated, and it appears that your implementation does
>>this.
>>
> Heck, isn't there some mention of also having an EOF marker written?
Right, but there is no requirement in Ada that EOF markers have any
particular representation. In particular, they might be written as <CR><LF>
sometimes, and simply "virtual" in other cases. (End-of-page markers are
almost always handled as "virtual" at the end of files, because no one wants
every file to end with <FF>.) Janus/Ada never writes any EOF or EOP
characters at the end of files; Get "manufactures" them if they are not
present at the end of a file. That makes reading from a text file much more
complex, but it also means that pretty much any text file can be read with
Text_IO and it will behave sensibly.
Randy.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-08-19 21:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-16 1:02 What's the cause of extra new line with Text_IO when program exit Zhu, Qun-Ying
2013-08-16 3:17 ` Jeffrey Carter
2013-08-17 17:54 ` Dennis Lee Bieber
2013-08-17 21:54 ` Jeffrey Carter
2013-08-19 21:58 ` Randy Brukardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox