Functions returning Error codes or actual info

Maurice Hill mhill at fiveliter.EBay.Sun.COM
Wed Sep 12 06:47:48 AEST 1990


flaps at dgp.toronto.edu (Alan J Rosenthal) writes:

>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.

Perhaps you could implement a different error strategy.  Instead of
returning an error code, set a global such as is done with errno.  

Errno is an index into an array of predefined error messages.  You can
access the list yourself or use the function perror("msg") to print out
your msg plus the error message that corresponds to errno.



More information about the Comp.lang.c mailing list