comp.lang.ada
 help / color / mirror / Atom feed
* End_Of_File but not really
@ 2006-12-07 18:00 Adam Beneschan
  2006-12-07 20:17 ` Jeffrey R. Carter
  2006-12-08  0:29 ` Randy Brukardt
  0 siblings, 2 replies; 10+ messages in thread
From: Adam Beneschan @ 2006-12-07 18:00 UTC (permalink / raw)


This is based on some of the things I've been saying on Maciej's thread
about the Get_Line problem.  I ran this test using GNAT.  Note that my
input file is a disk file, to avoid the additional issues that arise
with interactive files.

with Ada.Text_IO;
use Ada.Text_IO;
procedure IOTest is
    Line : String(1..100);
    Last : Integer;
    F    : File_Type;
    EOF  : Boolean;
begin
    Open(F, In_File, "f1");
    loop
        begin
            EOF := End_Of_File (F);
            Get_Line (F, Line, Last);
            if EOF then
                Put_Line
("End_Of_File returned TRUE but Get_Line did not raise an exception");
                exit;
            end if;
        exception
            when End_Error =>
                Put_Line ("End_Error raised");
                exit;
        end;
    end loop;
end IOTest;

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:

(1) The RM does not allow this behavior, and GNAT is broken.

(2) This behavior is what the RM requires.  To me, this means the RM is
broken---it just doesn't make sense to me that End_Of_File would return
True if there is more information in the file to get with Get_Line
(even if the information is "the presence of a blank line").  But
perhaps it's my own understanding that is broken; perhaps my
understanding of what End_Of_File is supposed to do is wrong, even
though I think it's what a reasonable person would expect a function
called "End_Of_File" to do.

(3) The behavior is implementation-defined according to the RM (because
the nature of terminators is implementation-defined), and it's possible
to have an implementation that never displays this message and an
implementation that is capable of displaying message both conforming to
the RM.  In this case, though, I'd say (3a) the RM is a little bit
broken, because even though the representation of terminators is
implementation-defined, it would seem that the definitions of
End_Of_File and End_Error ought to conform to each other, so that the
above message could never appear, and (3b) GNAT is broken, because even
though the RM allows it to implement Text_IO in a way that causes the
above message to appear, it shouldn't because it doesn't make sense.

So which is it?  Thoughts?  Comments?

                                      -- Adam




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-12-26  7:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-07 18:00 End_Of_File but not really Adam Beneschan
2006-12-07 20:17 ` Jeffrey R. Carter
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

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