Returning error codes from a function
Dave Jeffery
JI8 at psuvm.psu.edu
Wed Oct 31 03:48:03 AEST 1990
We would like to write a function that returns a pointer to void
(void *). In this function there are several conditions that can
occur that would be considered an error. Rather than simply
returning NULL we would like to return more detailed error information.
Several ideas have been discussed but one that seems to have the most
promise is to define several global void pointers and return them.
Please note that this is in a multi-tasking environment where a global
error code is not acceptable, and the overhead of passing additional
parameters is too high.
void *error1 = "error1";
void *error2 = "error2";
void *ourfun(int p1);
main() {
...
if (ourfun(10) == error1) ...
... }
void *ourfun(int p1) {
....
return error1;
... }
Our concerns are:
1. Does this violate ANSI C ?
2. Is it portable ?
In your replies, please site where in the ANSI C standard, or any
other publication, this issue is clarified.
----
Dave Jeffery JI8 at psuvm.psu.edu
More information about the Comp.lang.c
mailing list