Date: Mon, 10 May 1999 09:37:25 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Alain Magloire cc: djgpp-workers AT delorie DOT com Subject: Re: Quirky getch() (fwd) In-Reply-To: <199905092116.RAA26138@spock2.ECE.McGill.CA> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 Precedence: bulk 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.