Pascal --> C question

Eddie Wyatt edw at IUS1.CS.CMU.EDU
Tue Mar 15 03:25:34 AEST 1988


> 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 at ius1.cs.cmu.edu



More information about the Comp.lang.c mailing list