Pascal --> C question

mcdonald at uxe.cso.uiuc.edu mcdonald at uxe.cso.uiuc.edu
Mon Mar 21 23:58:00 AEST 1988


Rahul Desi wrote the following C program:
/* A "Hello world" program in three movements */
#include <stdio.h>

main()
{
   printf("He");  fflush(stdout);  printf("llo"); fflush(stdout); 
   printf(" wor"); fflush(stdout); printf("ld"); fflush(stdout);
   printf("\n");
}
and ran it in batch mode on VMS.
He got as output:

He
llo
 wor
ld

I ran it interactively, and it output "Hello world" [sic] (He forgot
the canonical !  ;-)  (hey! that's a great typo! a wink!) )

I ran it after doing a $define sys$output hello.out .
and when I type the hello.out file I get
He
llo
 wor
ld

The file "hello.out" is a standard VMS text file. I think that the four-
line file the program creates is correct. Remember that Dhesi didn't
put a 
        printf("Hello world\n");
statement in his file. He wrote it so that it was split into four
records by the flushes. He got the four records. Because standard
VMS text files always have records which logically end in 
carriage-return line-feed pairs, it prints the way it does. This seems
to be correct behaviour: a flush terminates a record. If he wanted
to output to a file where a flush did not terminate a record, but
rather a line-feed alone did, he should open the file as "byte-stream
terminated by line-feed". This is how VMS C by default opens text files.
But he didn't open the file himself, he used stdout, which VMS opens
in a predefined way, which appears to differ if it is going to the screen
or a disk file. All this goes to prove is that VMS is not Unix.
The VMS C compiler isn't broken.

Doug McDonald



More information about the Comp.lang.c mailing list