Reputation: 2227
in view of this and this, here is my strategy(similar to win32 api functions) :
1)Reserve return value for indicating success(non zero value),error(0).
2)use errno,perror to give more info. on the type of error.
3)use parameters to return values.
If this is OK then can I define my own error codes(not conflicting with the existing codes) and use errno to set/retrieve them. I don't think now I would be able to use perror with these codes(it will always say:unknown error) but I can define my own switch case based function to return description of the error code.I could define my own variable but much has already been done to make errno modern and thread safe.
eg:
int val;
if(MyPop(&val))
pintf_s("\n %d popped from my stack. . .",val);
else
printf_s(Myperror());
Thanks.
Upvotes: 1
Views: 3786
Reputation: 613491
I don't think anyone nowadays would design an error handling system like errno
. Even if errno
is implemented using thread-local storage it is still far from ideal—it is still a global variable at heart.
Since you don't have grown up error handling based on exceptions I would recommend returning error codes as function return values. This allows you to use the stack, avoid global state, and therefore be resilient to threads and re-entrant calling patterns.
Upvotes: 5