lkml.org 
[lkml]   [2007]   [Mar]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h)
Jan Engelhardt wrote:
> On Mar 16 2007 16:24, Richard Knutsson wrote:
>
>>>> char yesno_chr(const bool value)
>>>> {
>>>> return "ny"[value];
>>>> }
>>>>
>>>> char *yesno_str(const bool value)
>>>> {
>>>> return &"no\0yes"[3 * value];
>>>> }
>>>>
>
> static/extern const char *const yesno[] = {"no", "yes"};
> static inline const char *yesno_str(bool value)
>
Should we use "inline"? Isn't it better to leave that to the compiler?
Why the "const"?
> {
> return yesno[value];
> }
>
That's better :)
But I think a simple

static char *yesno_str(bool value)
{
return value ? "yes" : "no";
}
is to prefer, don't you? It is simpler and we don't need to deal with an unnecessary array (unless it may be used by itself, that is. Then I would go for your implementation).

> #or
> #define yesno_str(value) yesno[!!(value)]
>
Why not "(bool)value" instead? We cast all the other times we want a
something to be of a different kind.

Any thoughts where to put a function like this?

Richard Knutsson


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-03-17 02:05    [W:0.098 / U:0.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site