fclose(NULL)

Many Linux users seem to suffer from the delusion that Linux has the most standard behaviour, probably because it is the first UNIX-like operating system they use.

vim versus vi is a common one, but an interesting (and undefined behaviour) is closing a null pointer to a file. This is the sample code;

#include <stdio.h>
int main() {
	fclose(0);
	return 0;
}

Both HP-UX and Solaris will run this program without issue. Linux, will segfault. FreeBSD also seems angry. Granted, it's a stupid thing to do, but it isn't an inidcation of how other systems might react.

Mon, 8 Dec 2008 22:26:15 -0500 View History