www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/05/10/02:39:31

Date: Mon, 10 May 1999 09:37:25 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Alain Magloire <alainm AT rcsm DOT ece DOT mcgill DOT ca>
cc: djgpp-workers AT delorie DOT com
Subject: Re: Quirky getch() (fwd)
In-Reply-To: <199905092116.RAA26138@spock2.ECE.McGill.CA>
Message-ID: <Pine.SUN.3.91.990510093704.2882J-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sun, 9 May 1999, Alain Magloire wrote:

> stderr is an unbuffered stream, you should not have to do fflush(stderr).

Buffering can be changed by the application.  I agree that if the
stream is unbuffered, it shouldn't be flushed.  On the other hand,
fflush is almost a no-op in those cases anyway.

> But what is getch ?

It is a DOS-specific function that reads a single character from
stdin, without echoing the character and bypassing any buffering, both
in the library and in the OS.  By far the most popular use of it is to
pause the program until you press any key.

> int main() {
>       clrscr();
>       cout << "Hello World\n";
>       cout << "Sing along!";
>       getch();
>       return 0;
> }           
> 
> You're using two different APIs again, Iostreams and stdio(getch) or
> whatever API getch() is part of.

We all know that.  The DJGPP FAQ explains that at some length.  And
yet people still ask these questions.  I think ridding of these
questions is worth an overhead of a function call.

> I don't think you'll modify read() to fflush().

`read' is a Posix function, so we need to be careful not to contradict
the standards.  But `getch' is a non-standard function, and we can
change it at will.

Since even stdio functions in the current implementation flush stdout
when stdin is read in line-buffered mode, to prevent the FAQs like the
one above, I thought it would be a prudent thing to make `getch' do
the same.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019