From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: End_Of_File but not really
Date: Thu, 07 Dec 2006 20:17:22 GMT
Date: 2006-12-07T20:17:22+00:00 [thread overview]
Message-ID: <mF_dh.307365$1i1.293847@attbi_s72> (raw)
In-Reply-To: <1165514423.562024.70510@j72g2000cwa.googlegroups.com>
Adam Beneschan wrote:
>
> If I try this on Linux, on a file whose bytes are abc<LF><LF>, then the
> message "End_Of_File returned TRUE but Get_Line did not raise an
> exception". This strikes me as bizarre---if End_Of_File returns True,
> then a subsequent read operation should raise an End_Error, but that
> isn't what's happening. One of these must be true:
This is the behavior I described in an earlier post.
From a Text_IO point of view, this is a degenerate file, since it
doesn't end in <EOL><EOP><EOF>. But consider if you wrote this file with
Text_IO:
File : Ada.Text_IO.File_Type;
...
Ada.Text_IO.Create
(File => File, Mode => Ada.Text_IO.Out_File, Name => "f1");
Ada.Text_IO.Put_Line (File => File, Item => "abc");
Ada.Text_IO.Put_Line (File => File, Item => "");
Ada.Text_IO.Close (File => File);
Then you would get what Text_IO considers a correct text file, containing
abc<EOL><EOL><EOP><EOF>
(however those are encoded for your OS/compiler). After the first
Get_Line, the remainder of the file contains <EOL><EOP><EOF>--the
definition of the condition when End_Of_File returns True. Yet clearly
there is an empty line still to be read in that file, since it was
created by writing "abc" followed by writing an empty line. So the
situation you describe is true even for a file written by Text_IO:
End_Of_File returns True and Get_Line reads an empty string.
Another way of looking at it: End_Of_File looks ahead and sees
<EOL><EOP><EOF>, so it returns True. Get_Line reads <EOL>, so it sets
Last to Item'First - 1 and returns.
I'm not saying this is sensible, just that it's what the RM specifies.
Text_IO would be better without pages, and without column and line (and
page) counting.
--
Jeff Carter
"Every sperm is sacred."
Monty Python's the Meaning of Life
55
next prev parent reply other threads:[~2006-12-07 20:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-07 18:00 End_Of_File but not really Adam Beneschan
2006-12-07 20:17 ` Jeffrey R. Carter [this message]
2006-12-07 23:25 ` Adam Beneschan
2006-12-08 0:29 ` Randy Brukardt
2006-12-08 17:02 ` Adam Beneschan
2006-12-08 23:02 ` Randy Brukardt
2006-12-24 0:54 ` Craig Carey
2006-12-26 7:44 ` Craig Carey <research@ijs.co.nz>
2006-12-10 4:57 ` Steve
2006-12-11 22:49 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox