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=FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Blady Newsgroups: comp.lang.ada Subject: Weird behavior of Get character with trailing new lines. Date: Fri, 22 Sep 2023 21:30:15 +0200 Organization: A noiseless patient Spider Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 22 Sep 2023 19:30:16 -0000 (UTC) Injection-Info: dont-email.me; posting-host="1ea2f90b6038eae0d113dfd19a1f3943"; logging-data="415723"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yfdM6+p+1ebmmYMtj+cNA" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Cancel-Lock: sha1:VrxHpR1eublGcs5Bk7CIEt3Q/uc= Content-Language: fr, en-US Xref: news.eternal-september.org comp.lang.ada:65694 List-Id: Hello, I'm reading a text file with Get character from Text_IO with a while loop controlled by End_Of_File. % cat test_20230922_get_char.adb with Ada.Text_IO; use Ada.Text_IO; procedure test_20230922_get_char is procedure Get is F : File_Type; Ch : Character; begin Open (F, In_File, "test_20230922_get_char.adb"); while not End_Of_File(F) loop Get (F, Ch); Put (Ch); end loop; Close (F); Put_Line ("File read with get."); end; begin Get; end; All will be well, unfortunately not! Despite the End_Of_File, I got an END_ERROR exception when there are several trailing new lines at the end of the text: % test_20230922_get_char with Ada.Text_IO; use Ada.Text_IO;procedure test_20230922_get_char is procedure Get is F : File_Type; Ch : Character; begin Open (F, In_File, "test_20230922_get_char.adb"); while not End_Of_File(F) loop Get (F, Ch); Put (Ch); end loop; Close (F); Put_Line ("File read with get."); end;beginGet;end; Execution of ../bin/test_20230922_get_char terminated by unhandled exception raised ADA.IO_EXCEPTIONS.END_ERROR : a-textio.adb:517 The code is compiled with GNAT, does it comply with the standard? A.10.7 Input-Output of Characters and Strings For an item of type Character the following procedures are provided: procedure Get(File : in File_Type; Item : out Character); procedure Get(Item : out Character); After skipping any line terminators and any page terminators, reads the next character from the specified input file and returns the value of this character in the out parameter Item. The exception End_Error is propagated if an attempt is made to skip a file terminator. This seems to be the case, then how to avoid the exception? Thanks, Pascal.