Functions returning Error codes or actual info

Alan J Rosenthal flaps at dgp.toronto.edu
Wed Sep 12 02:15:31 AEST 1990


vrm at cathedral.cerc.wvu.wvnet.edu (Vasile R. Montan) writes:
>   I am making a set of functions which return different types of
>values: strings, integers, doubles, etc.  For example:
>          char *get_string();
>However, I would also like the function to return an error code if the
>function fails.  I cannot just return a NULL pointer because I want
>the function to be the same as all of the other get_xxx's.

A method you didn't mention is to return a null pointer, and have a #defined
constant for this.  If you return some kind of distinguished value already for
the integer functions, such as -1, you may want to have:

	#define INTERROR (-1)

in your .h file.  So put:

	#define STRINGERROR ((char *)0)

in your .h file as well.



More information about the Comp.lang.c mailing list