delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/27/03:15:18

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf/getch problem
Date: Mon, 26 Jan 1998 23:52:52 -0800
Organization: Alcyone Systems
Lines: 56
Message-ID: <34CD9254.7A9FB1C6@alcyone.com>
References: <34CC5211 DOT 57270346 AT alcyone DOT com> <19980127034901 DOT WAA22568 AT ladder02 DOT news DOT aol DOT com>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Myknees wrote:

> I hear many people say that, and it makes sense on an abstract level,
> since
> file (or stdin / out) I/O is different from console I/O.  But no one
> has ever
> said what concrete bad would really come of it.  ...printf("conio &
> stdio can't
> get along\n"); getch();...  Will this code run slowly or become
> unstable or be
> less portable or something?
> 
> I know this is really a C question, but I'm hankerin' to ask the djgpp
> people
> who say this stuff what they really mean.

The problem with mixing stdio and conio* is that, because they are not
defined within the same standard (in fact, conio is not defined by any
standard, except by example).  As such, the behavior that occurs when
they interact is undefined.  Theoretically, anything can happen.

Naturally, if you know the precise nature of the interaction between
stdio and conio, then you will be able to use them together -- using the
particular compiler you're using and on the particular platform you're
on.  If you switch to another compiler or platform (which naturally
still supports both stdio and conio, otherwise this is a moot point),
then you're back to square one.

And finally, there are possible performance penalties for mixing stdio
and conio.  When you come across a situation where two packages think
they're king of the hill, so to speak, and think they have free reign,
using them both (carefully) with one another will undoubtedly result in
some performance penalty -- at the very least, it won't be faster.  And
since you're linking in both libraries, your executable is going to be
bigger.

It doesn't make much sense to use _both_ stdio and conio to meet some
programming goal, since they're each intended to be used in their own
right, and not together.  After all, if all you want to do is print
something and wait for a keypress, why aren't you using cprintf and
getch (both conio), instead of printf (stdio) and getch (conio), causing
all of these problems in the first place?

. 

This stuff applies to any two (or more!) mutually-exclusive I/O
mechanisms; stdio and conio is just an example.  It is just as
applicable to, say, stdio and curses.

-- 
         Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                       Alcyone Systems / http://www.alcyone.com/max/
  San Jose, California, United States / icbm://+37.20.07/-121.53.38
                                     \
                       "Life may be / the product of imperfections."
                                   / (Marclo Gleiser)

- Raw text -


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