[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080922170013.GF16625@ghostprotocols.net>
Date: Mon, 22 Sep 2008 14:00:13 -0300
From: Arnaldo Carvalho de Melo <acme@...hat.com>
To: Gerrit Renker <gerrit@....abdn.ac.uk>, davem@...emloft.net,
dccp@...r.kernel.org, netdev@...r.kernel.org
Subject: Re: [PATCH 2/5] dccp: Implement lookup table for
feature-negotiation information
Em Mon, Sep 22, 2008 at 05:45:54PM +0200, Gerrit Renker escreveu:
> | > --- a/include/linux/dccp.h
> | > +++ b/include/linux/dccp.h
> | >
> | > +
> | > +static int dccp_feat_default_value(u8 feat_num)
> | > +{
> | > + int idx = dccp_feat_index(feat_num);
> | > +
> | > + return idx < 0 ? : dccp_feat_table[idx].default_value;
> | > +}
> |
> | [acme@...pio ~]$ cat dd.c
> | #include <stdio.h>
> |
> | int main(void)
> | {
> | int idx = -2;
> |
> | printf("%d\n", idx < 0 ? : 10);
> | printf("%d\n", idx < 0 ? idx : 10);
> | return 0;
> | }
> | [acme@...pio ~]$ ./dd
> | 1
> | -2
> | [acme@...pio ~]$
> |
> | Which one do you want? The boolean result as the value to be returned or
> | the index if it is < 0?
> |
> It is the first value. The test is only there to avoid accessing the
> array with an invalid index, which would happen if an unknown `feat_num'
> is passed - as for unknown features there is no default value.
The above explanation would be good to have as a comment, as it was not
so obvious from a first sight. I think that even having it explicit
would be clearer:
return idx < 0 ? 1 : dccp_feat_table[idx].default_value;
But then, if an unknown feat num is passed shouldn't the code bailout in
some other fashion than returning the result of a boolean expression and
not accessing the defaults table?
- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists