On Thu, 2005-10-20 at 16:23 -0600, Bruce Shaw wrote:
> The one
> place where I did call it correctly in hindsight looks kind of
> bass-ackwards:
>
> if (!getKstatInt("unix", "system_misc", "nproc", &nproc))
>
> ...or in other words "if not kstat didn't work" with is a double-negative.
This style of code is extremely common, and so will be fairly second
nature to most experienced C programmers. But in general, unless the
function concerned is specifically defined as returning a boolean value,
it's a somewhat lazy style of programming.
A generally clearer approach is to explicitly compare the return
value with the appropriate error return code:
if (getKstatInt("unix", "system_misc", "nproc", &nproc) == 0)
or
if (getKstatInt("unix", "system_misc", "nproc", &nproc) != 0)
This doesn't rely on the particular semantics of mapping numeric
values to true/false.
(There's also an good argument for putting the constant first,
though personally I strongly dislike this layout).
> I propose to change it to: (OK, I'm lying. I already changed it
> and I'm trying to avoid getting it yanked)
It's your code, Bruce.
As long as it works correctly, nobody is going to pull rank and
override you. We might argue long and hard about how poor a
choice you've made over this or that bit of code - but unless
it's actually doing something wrong, then you get to decide how
it should be.
Dave
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders