Path: utzoo!mnetor!uunet!husc6!mit-eddie!bbn!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: Pascal --> C question Message-ID: <1120@PT.CS.CMU.EDU> Date: 14 Mar 88 17:25:34 GMT References: <12340@brl-adm.ARPA> <2351@bsu-cs.UUCP> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 30 > Another interesting optimization done by a VMS compiler, that competing > vendors never thought of doing, is this. If your C program contains > > fflush(stdout); > > the VMS C compiler will optimize this into: > > if (F$MODE == INTERACTIVE) /* if interactive run */ > fflush(stdout); > else > printf("\n"); /* if batch run */ I hope that the VMS C compiler doesn't do this. fflush doesn't force a newline. It writes the output buffer. Also I don't think that the compiler really does this anyway. The most logically place to optimize the fflush is to either use a macro definition #define fflush(hi) ((F$MODE == INTERACTIVE) ? fflush(hi) : 0) or add the test to fflush. Thirdly, this optimization is somewhat unsafe. If the program was to crash immediately after the fflush call, the output that is suppose to be written will not be. That is unless they have made provision to fflush output on fatal errors. -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu