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-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,NICE_REPLY_A, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: wait does not perform as expected Date: Thu, 23 Feb 2023 19:14:38 +0100 Organization: A noiseless patient Spider Message-ID: References: <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 23 Feb 2023 18:14:36 -0000 (UTC) Injection-Info: reader01.eternal-september.org; posting-host="5e09243eb177348401e741ec3b255505"; logging-data="2039485"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18w2z2PJTGPK5G+l5w2YGgrp0qudAraDSg=" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Cancel-Lock: sha1:DNej4CQ24YWu6gw3Hdj6szc0EIQ= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:64972 List-Id: On 2023-02-23 18:35, Niklas Holsti wrote: > On 2023-02-23 16:26, AdaMagica wrote: >> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1: >>> On my system, Get_Immediate does /not/ use the inputs collected (but not >>> "consumed") by Look_Ahead, but instead checks if there are _new_ input >>> keystrokes. If there are none, Get_Immediate returns "not Available" >>> (Hit is False) and so the loop continues. >> >> Are you sure? > > That is what I observe. The implementation of Look_Ahead calls getc followed by ungetc. Thus it blocks until an input if there is no buffered. And not just input, but for a line or file end. As for ungetc POSIX layer under Windows, ungetc probably does not work correctly, I am too lazy to verify. One possibility is that file positioning (fseek etc) kill unget buffer. In any case, subprograms like Look_Ahead, End_Of_File etc exit strictly for decoration, not for any practical reason. As a rule of thumb no program should ever use them. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de