From: "John M. Aldrich" Newsgroups: comp.lang.c,comp.os.msdos.djgpp Subject: Re: A funny thing happened! Date: Tue, 12 Aug 1997 21:21:46 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 53 Message-ID: <33F0D3EA.528A@cs.com> References: <33EE4447 DOT 24E09407 AT nospam DOT net> <871305859snz AT genesis DOT demon DOT co DOT uk> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp105.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Lawrence Kirby wrote: > > As to your question what you appear to be seeing is stdout fully buffered. > The standard says that stdout should be set by the implementation as > fully buffered if and only if it can determine that it doesn't refer to > an interactive device. It would be reasonable to say that your screen is > an interactive device so the compiler is in error making stdout fully > buffered. However it is left to the implementation to define what > "interactive device" means. So if DJGPP doesn't consider the screen to > be an interactive device it is within its rights. It is a case that DJGPP > might be violating the spirit of the standard but maybe not the letter. I suppose that "fully buffered" is defined somewhere as well, or we'll be chasing each other in circles over its proper meaning. However, stdout in DJGPP is line buffered by default, which AFAIK conforms with ANSI requirements. There is a good reason for this; the overhead of the mode switches required to send text to the DOS file handling functions is high enough to make line buffering a good tradeoff for speed. It's really simple to work around or disable it, though. But the major thing that you've overlooked is that conio and stdio functions were not meant to be mixed. stdio reads and writes data to the DOS file handling routines, while conio reads directly from the BIOS keyboard and writes to text video memory. The two are mutually incompatible; it's merely coincidence that they work together on some compilers. One of the features of the stdout buffering in DJGPP is that if you call an input function that reads from stdin, the buffer is automatically flushed. The following works perfectly, although it requires a carriage return after the character is typed: printf( "Type a character: " ); getchar(); The advantage to conio functions is that you really can read a single character at a time. But if you use conio input routines, you ought to use conio output routines as well. The following also works without fiddling with buffers: cprintf( "Type a character: " ); getch(); Of course, you can't redirect conio input and output like you can with stdio. C'est la vie. -- --------------------------------------------------------------------- | John M. Aldrich | "Sin lies only in hurting other | | aka Fighteer I | people unnecessarily. All other | | mailto:fighteer AT cs DOT com | 'sins' are invented nonsense." | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------