Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!sun-barr!lll-winken!uunet!bywater!arnor!larios!db3l From: db3l@ibm.com (David Bolen) Newsgroups: comp.os.os2.programmer Subject: Re: printf() will work in PM programs Message-ID: Date: 9 Nov 90 23:03:19 GMT References: <21079@ttidca.TTI.COM> Sender: news@arnor.uucp (NNTP News Poster) Organization: Laboratory Automation, IBM Thomas J. Watson Research Center Lines: 41 In-Reply-To: terence@ttidca.TTI.COM's message of 7 Nov 90 19:58:11 GMT In article <21079@ttidca.TTI.COM> terence@ttidca.TTI.COM (Terence Davis) writes: >It is possible to use printf() in PM programs if you can live with seeing >the output after program execution. I discovered that if I run the PM >program in a cmd.exe window inside my editor (Epsilon) I will see the >printf'ed strings when I exit the PM program. This is not so good for >following the execution trail of a program while it's running, but if >you want to see the values of variables it works great. Actually, you do see the output while the program runs, but subject to whatever buffering the C library is performing on the standard output screen. This works because Epsilon runs concurrent processes in their own full-screen session, which it has VioRegistered to get all the Vio calls for. Normally, stdout for a PM program is discarded rather than showing up in any window, but since Epsilon is handling the output requests it can catch them and put them in its buffer anyway. I've used this a lot in my PM programming (I'm a big fan of printf-debugging) and found it invaluable. Try adding some fflush(stdout) calls after your printfs and/or issue a setbuf() call on the stdout file with a NULL pointer to disable buffering, and you should see your output as your program runs. Of course, if you can live with output following a program's execution, you can always use printf and just redirect the output of the program to a file, then look at the file later. This does run into problems though if your program TRAPs since not everything may be flushed to the file (especially if C buffering was involved). -- David Bolen -- /-----------------------------------------------------------------------\ \ David Bolen / | Laboratory Automation, IBM Thomas J. Watson Research Center | / P.O. Box 218, Yorktown Heights, NY 10598 \ | - - - - - - - - - - - - M i t h r a n d i r - - - - - - - - - - - - | | Internet : db3l@ibm.com | Bitnet : db3l@yktvmv | | Usenet : uunet!bywater!arnor!larios!db3l | Phone : (914) 945-1940 | \-----------------------------------------------------------------------/