From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5afe598156615c8b,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeed-0.progon.net!progon.net!news-zh.switch.ch!switch.ch!cernne03.cern.ch!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Get_Line problem (GNAT bug?) Date: Wed, 06 Dec 2006 15:25:31 +0100 Organization: CERN News Message-ID: NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Trace: cernne03.cern.ch 1165415132 2248 137.138.37.241 (6 Dec 2006 14:25:32 GMT) X-Complaints-To: news@@cern.ch NNTP-Posting-Date: Wed, 6 Dec 2006 14:25:32 +0000 (UTC) User-Agent: Thunderbird 1.5.0.8 (X11/20061113) Xref: g2news2.google.com comp.lang.ada:7820 Date: 2006-12-06T15:25:31+01:00 List-Id: Hi, Consider: with Ada.Text_IO; procedure Hello is use Ada.Text_IO; Input_Line : String(1..100); Last_Index : Integer range 0..100; begin loop Put("What's your name? "); exit when End_Of_File; Get_Line(Input_Line, Last_Index); if Last_Index >= Input_Line'First then Put("Hi, "); Put(Input_Line(1..Last_Index)); New_Line; else Put("You have funny empty name."); New_Line; end if; end loop; end Hello; (please focus on the Get_Line problem here) It should be obvious what the program does, except that the behaviour in the case of empty input line is a bit strange. Below, in the right-hand column I describe what keys were pressed: $ ./hello What's your name? Maciek -- M a c i e k ENTER Hi, Maciek What's your name? -- ENTER -- ENTER You have funny empty name. What's your name? -- ENTER You have funny empty name. What's your name? -- EOF $ As you see, the first ENTER was somehow "swollowed", creating an empty line in the console (that's the echo of what user typed), but still blocking in Get_Line. All subsequent ENTERs seem to be handled correctly, which means that Get_Line returns with Last_Index < Input_Line'First. I was already suggested that it might be a GNAT feature. If yes, it seems to be persistent, because I see it with two different versions. Of course, I expect that empty lines are handled uniformly. Any thoughts? -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/