Returning error codes from a function

Doug Gwyn gwyn at smoke.brl.mil
Wed Oct 31 09:48:07 AEST 1990


In article <90303.114803JI8 at psuvm.psu.edu> JI8 at psuvm.psu.edu (Dave Jeffery) writes:
>   1. Does this violate ANSI C ?

No, it's okay.  The most important reference is 3.3.16.1.

>   2. Is it portable ?

No, because pre-ANSI compilers generally did not support void*.
Since these error coded are really char* anyway, why not just
use char*.  In fact a typedef would be nice:
	typedef char *ErrorCode;
	typedef const char ErrorDef[];	/* for unchanging constants */
	#define NO_ERROR 0	/* or some other form of null pointer */

	static ErrorDef	error1 = "error1";
	...

	ErrorCode ourfun(args) {
		...
		return error1;
	}
There are all sorts of possible variations on this theme.



More information about the Comp.std.c mailing list