we would define that code in the .h file where the function prototype is declared.
UseI would recommend against this as you don't have anything to reduce the space for potential numbering conflicts.
Instead, use a common header file providing error codes for both your client and server applications. Alternatively As an alternative, the client file can simply be a subset of the server error code file.
Within the common header file, each major area of your application will get a sequence of error numbers. And from within each major area, you can assign subsets of error code ranges to the modules within that layer.
For example, say you have a session manager, a business logic, and a database access layerlayers in your server application. Your header file might be broken down like this:
/*
* our error.h file
*/
/* Common Errors 0 - 99 */
#define SUCCESS 0
#define GENERIC_ERROR 1
/* Session Manager errors 100 - 199 */
/* Login issues 100 - 110 */
#define BAD_PASSWORD 101
/* session issues 120 - 125 */
/* other session issues 150 - 162 */
#define SOMETHING_ELSE 150
/* Business logic errors 200 - 299 */
/* Database errors 300 - 399 */
#define INVALID_CONNECTION 300
The advantage of this approach is it cuts down the overall space where conflicts in numbering can occur. Potential conflict is limited to the areas where two or more developers are working simultaneously.
By having a common error header file, your developers can check out the file as needed to create a new error and make sure they are claiming an unused number at that point in time.
Potential pitfalls with this approach are when developers don't frequently commit their local copy of the error header. But that's a process issue that will usually work its way out once those developers have had to deal with it a few times. And since they are referring to the error number through the #define it's not that big of a change.
Another pitfall is when you misjudge the range required for a layer or sub-module. The easiest way to avoid this is to pre-allocate really large ranges for each layer and sub-module. And from there, you should be able to trim from one sub-module in order to give greater range to another. And there's nothing that says the ranges have to be contiguous.