Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Dave Korn" To: Subject: RE: stderr and clearmake Date: Thu, 11 Nov 2004 17:02:40 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In-Reply-To: <4193827C.7030105@comcast.net> Message-ID: X-OriginalArrivalTime: 11 Nov 2004 17:02:40.0390 (UTC) FILETIME=[40B5BA60:01C4C810] > -----Original Message----- > From: Aaron Conole > Sent: 11 November 2004 15:17 > To: Dave Korn > Subject: Re: stderr and clearmake :) Aaron, let's keep this on the mailing list, I charge extortionate rates for private consultancy, and anyway, 1) there are a lot more people able to help and offer advice on the list than just me and they might think of or know things I don't, 2) if I make any mistakes or offer bad advice someone will pull me on it fairly sharpish, 3) and of course by keeping the conversation on the list it goes into the web archives, where it is searchable and may help out anyone who runs up against the same problem in the future. Thanks. Now on with the code: > Dave Korn wrote: > >>-----Original Message----- > >>From: cygwin-owner On Behalf Of Aaron Conole > >>Sent: 11 November 2004 14:08 > >>I've written a program to print out a message on stdout and then on > >>stderr. The output is as follows: > >>aconole AT ACONOLE ~ > >>---------------------------- > >>$ ./stderr-test.exe > >>This is stderr! > >>This is stdout! > >>---------------------------- > >>The code is: > >>------------------------ > >>#include "stdio.h" > >> > >>int main(){ > >> fprintf(stdout, "This is stdout!\n"); > >> fprintf(stderr, "This is stderr!\n"); > >> return 0; > >>} > >>------------------------ > >>As you can see, for some reason stderr and stdout are being > >>manipulated in some odd fashion, > > No they aren't. That's exactly the output you'd expect to > see from that > >program. What on earth are you expecting to happen? > I'm expecting stderr after stdout. I'm seeing stderr before > stdout. At > first I assumed that it had something to do with the way buffers were > being flushed, but under a cmd window (djgpp compiled > executable) I get > stdout before stderr, as I expect. I don't think you have any right to expect that. IIRC, there are _zero_ guarantees provided by the C language standard and the C stdio library specification about the order in which stdio buffers will be flushed. It's entirely at the whim of the runtime library, and as you can see, when a program reaches the termination routines under cygwin, it chooses to flush the stderr buffer before the stdout buffer. Use fflush explicitly if you need to manage the order: int main(){ fprintf(stdout, "This is stdout!\n"); fflush (stdout); /* force that line to be emitted */ fprintf(stderr, "This is stderr!\n"); fflush (stderr); /* now force the next line to be emitted */ return 0; } cheers, DaveK -- Can't think of a witty .sigline today.... -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/