>> > >I'd like to lodge a bitter complaint about the return codes used by
>> > >queue_work() and related functions:
>> > >
>> > > Why do the damn things return 0 for error and 1 for success???
>> > > Why don't they use negative error codes for failure, like
>> > > everything else in the kernel?!!
>> >
>> > It's a standard programming idiom: return false (0) for failure, true
>> > (non-zero) for success. Boolean.
>>
>> There are at least 3 idioms:
>>
>> 1) return 0 on success, -E on fail¹.
>> 2) return 1 on YES, 0 on NO.
>> 3) return valid pointer on OK, NULL on fail.
I wrote something up some time ago,
http://svn.sourceforge.net/viewvc/vitalnix/trunk/src/doc/extra-aee.php?revision=1
>Functions can return values of many different kinds, and one of the most
>common is a value indicating whether the function succeeded or failed.
>Such a value can be represented as a "status" integer (0 = success, -Exxx
>= failure) or a "succeeded" boolean (1 = success, 0 = failure).
>
>Mixing up these two sorts of representations is a fertile source of
>difficult-to-find bugs. If the C language included a strong distinction
>between integers and booleans then the compiler would find these mistakes
>for us... but it doesn't.
Recently introduced "bool".
Jan Engelhardt
--
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]