Regression with dev_null.f90

Steve Kargl sgk@troutmask.apl.washington.edu
Sat May 21 19:30:00 GMT 2005


On Sat, May 21, 2005 at 09:23:36PM +0200, Thomas Koenig wrote:
> On Sat, May 21, 2005 at 11:54:43AM -0700, Steve Kargl wrote:
> 
> > It seems the semantics of reading from /dev/null is 
> > system dependent.
> 
> What happens if you read from /dev/null on freebsd?  As a short
> test, could you send the output of "strace cat < /dev/null"
> (if you have strace, of course) ?

gfortran behavior appears to depend on the POSIX definition of
/dev/null.  From http://www.opengroup.org/onlinepubs/009695399/toc.htm

   /dev/null -- An infinite data source and data sink.  Data written
   to /dev/null shall be discarded.  Reads from /dev/null shall always
   return end-of-file (EOF).

This program prints 

i = 5
j = 1

#include <stdio.h>
#include <stdlib.h>
int main(void) {
	int i=0,j;
	FILE *fp;
	fp = fopen("/dev/null", "r");
	while(fread(&j, sizeof(int), 1, fp) != 1) {
		i++;
		if (i == 5) break;
	}
	printf("i = %d\n", i);
	if (j == EOF)
		printf("EOF\n");
	else
		printf("j = %d\n", j);
	return 0;
}


-- 
Steve



More information about the Fortran mailing list