Error Checking in C

utzoo!decvax!harpo!seismo!rocheste!mayer utzoo!decvax!harpo!seismo!rocheste!mayer
Mon Oct 25 19:59:40 AEST 1982


I would like to hear about styles of error checking in C.  The standard
technique is to return status values from functions, and to check the
results after each call.  Unfortunately, this obscures the normal flow
of control.  When I want to say:

	source = fopen(source_file, "r");

I have to write:

	source = fopen(source_file, "r");
	if (source == NULL) {
		...
		}
or
	if ((source = fopen(source_file, "r")) == NULL) {
		...
		}

How many people do you know that check for errors after a write?

Most modern languages, such as MESA or ADA, have explicit exception
handling constructs.  Would exception handling be a good extension to
C?  Would style conventions help?  Are things ok as they stand?

			Trembling, but nevertheless willing to sign my name
			Jim Mayer
			seismo!rochester!mayer
			allegra!rochester!mayer



More information about the Comp.lang.c mailing list