From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-91-241.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.0 required=3.0 tests=none autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Weird behavior of Get character with trailing new lines. Date: Sun, 24 Sep 2023 09:50:48 +0200 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 24 Sep 2023 07:50:48 -0000 (UTC) Injection-Info: dont-email.me; posting-host="ea8d2897c5498918a6f79f457b09b917"; logging-data="1343172"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sZtLQtgwrJgItrywY29xF+aCqF/pO6EA=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:RaQ4kVDxwzSV+eWLpaCtOvwDd88= Content-Language: en-US In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:65710 List-Id: On 2023-09-23 16:03, Niklas Holsti wrote: > On 2023-09-23 12:25, Dmitry A. Kazakov wrote: >> You exit the loop and do whatever is necessary there. > > That is exactly what happens in the "while not End_Of_File" loop. It does not because you must handle I/O errors and close the file. > If you want to use End_Error instead, you have to add an exception > handler, and if you want to stay in the subprogram's statement sequence > without entering the subprogram-level exception handlers, you have to > add a block to contain the reading loop and make the exception handler > local to that block. You always have to in order to handle I/O errors. > To me that looks like adding code -> more complex. Of course not much > more complex, but a little, as I said. No, it is simpler if the code is production code rather than an exercise. Consider typical case when looping implements reading some message, block etc. You have loop read something read another piece read some count read a block of count bytes ... You cannot do it this way if you use end of file test because you must protect each minimal input item (e.g. byte) by the test. It is massively obtrusive and would distort program logic. You will end up with nested ifs or else gotos. >> Testing for the file end is unreliable and non-portable. Many types >> of files simply do not support that test.In other cases the test is >> not file immutable with the side effects that can change the program >> logic. > > I suppose you are talking about the need for End_Of_File to possibly > read ahead past a line terminator? If not, please clarify. Yes, reading ahead and also issues with blocking and with race condition in shared files. Then things like sockets do not have end of file, connection drop is indicated by an empty read. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de