On Fri, Feb 07, 2003 at 03:18:41PM +0200, guy keren wrote: > 3. the function returns the error code by itself (with either a > per-function errors enum, or a global list of error codes - with one > value for 'success'). this puts consistency into the code (every > function that might fail reports an error code) - while making the > interface less convinient, when the funciton could sometimes have > returned a pointer (e.g. the 'fopen' functoin returns a pointer to a > FILE on success, or NULL on failure - and this works because it can > report the error code in the global 'errno' variable).
I like this mode, and the single project every Linux user uses uses it. You return -ERRNO to signify error, and 0 on success. As for a less convenient, either you pass the 'errno' variable, or the pointer parameter by reference. Another alternative is use the ugly "ERR_PTR" and "PTR_ERR" macros, to return a small numeric value (errno) in the high bits of a pointer, when the function returns a pointer. > i wonder what people here have to add regarding these models, or regarding > other models (again - for the "C" language) they have used, or wanted to > try to use. I've used all three, and the most important issues have been: 1. Always remain consistent. Make sure that all functions return error values in the same range, or use the same value(s) to return an error or success. 2. Global errno is bad, because you might inadvertently change its value by making a different call before checking it. 3. Each function having its own return codes is not consistent, and thus breaks point (1) above. For new code I write (and even old code I have occasion to modify), I always use the kernel's -ERRNO for failure, 0 for success mode. > if you comment - please state if you're talking about somehting you used, > something you've started using lately, or something you didn't yet use. or > if its soemthing you've read about somewhere. and please be fair - i.e. > when you describe your magnificent no-problem error reporting system, > please also state what are the bad parts of it - where it was annoying, > what in it would you improve if you had the time, or if you had an idea > how to do, etc. I really dislike the ERR_PTR and PTR_ERR macros mentioned above. If I was rewriting the kernel, I would probably make all those places pass the pointer by reference and return an int. -- Muli Ben-Yehuda http://www.mulix.org http://syscalltrack.sf.net -------------------------------------------------------------------------- Haifa Linux Club Mailing List (http://www.haifux.org) To unsub send an empty message to [EMAIL PROTECTED]