Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!agate!pasteur!ames!pacbell!att-ih!ihnp4!inuxc!iuvax!pur-ee!uiucdcs!uxc.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Pascal --> C question Message-ID: <225800014@uxe.cso.uiuc.edu> Date: 17 Mar 88 13:51:00 GMT References: <302@goofy.megatest.UUCP> Lines: 42 Nf-ID: #R:goofy.megatest.UUCP:302:uxe.cso.uiuc.edu:225800014:000:1868 Nf-From: uxe.cso.uiuc.edu!mcdonald Mar 17 07:51:00 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 */ > -- > Rahul Dhesi UUCP: !{iuvax,pur-ee,uunet}!bsu-cs!dhesi >I hope the compiler doesn't do this "optimization". It is not correct. >Flushing the stdio buffer should not insert a newline '\n' into the output >stream. >I don't know much about VMS. Is it possible to connect two processes >by means of a pipe fed on the inflow side by stdout? Consider two >processes, so connected, which send messages through the pipe, encoded >as text. In this case, the fflush() is required to assure that a message >is dispatched through the pipe. Is this application's F$MODE == INTERACTIVE? Perhaps you should understand VMS before making such comments. You see, VMS is not a flavor of UNIX. It is an entirely different operating system. Its file system is entirely unlike Unix's. There are many different TYPES of files. For certain kinds of files, outputting a \n in C will flush the buffers, AND is REQUIRED at the end of a file. Ordinary text files absolutely must end in a way that is indicated in C by /n. No particular character is actually placed in a file to represent this; it is indicated by the record structure. However, what is funny is that, by default, stdout is NOT a standard text file in the version of VMS C that we use. I seriously doubt that such behaviour is a bug though, as I've found that VMS C works quite well (except that stdout is not an ordinary text file.) Any genuine VMS gurus want to give the full explanation? Doug McDonald