returning an error code from a function that has a pointer return type
I have tried several google searches, but probably use the wrong keywords to find this.
I have a function that returns a pointer type, now if the function detects an error condition I would like the caller to be able to check the returned type for a specific error condition instead of only being able to return NULL as a failure indication.
I understand that pointers are numeric values int/long etc. but what's the best approach to do this and make sure I don't define a possible proper pointer value as an error code?
example of what I would like to achieve (not actual code used);
#define BADPARAMETER -1
void* myfunc(int myparam)
if (myparam < 0) return BADPARAMETER;
Probably has been done before, so any pointers to a solution are appreciated.
result = myfunc(somevalue);
if (result == BADPARAMETER)
.... handle returned error