Re: [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h)

From: Richard Knutsson
Date: Fri Mar 16 2007 - 21:02:53 EST


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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/