I have a dll with a c interface, the functions of which will return error codes, I will also provide an additional function that returns the last error. Does this sound sensible? can anyone point me at any examples that i can use as a template please?
Share
That would entail having an
errno-style global variable holding the last error, right? I’d advise against that, as it would make your library hard to use in a multithreaded application, unless you use thread-local storage. Still, if you want to do this, then the standard C library with itserrnovariable/macro would be a good example.A simpler and, IMHO, better approach is to just return error codes and if necessary provide some functions that operate on your error codes; e.g., you might want to have a
mylib_strerrorto convert them to human-readable string representations. So, the usage would look likeA good example of this style is the
getaddrinfoAPI specified in RFC 3493.