From: Richard Knutsson <ricknu-0@student.ltu.se>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
Kernel Janitors List <kernel-janitors@lists.osdl.org>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h)
Date: Sat, 17 Mar 2007 01:59:32 +0100 [thread overview]
Message-ID: <45FB3D74.2040907@student.ltu.se> (raw)
In-Reply-To: <Pine.LNX.4.61.0703170019010.23117@yvahk01.tjqt.qr>
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
prev parent reply other threads:[~2007-03-17 1:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <45F95351.60308@student.ltu.se>
[not found] ` <39e6f6c70703152036m778ea054gf32723d0eda2be68@mail.gmail.com>
2007-03-16 15:24 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?) Richard Knutsson
2007-03-16 16:33 ` Bernd Petrovitsch
2007-03-16 17:09 ` Richard Knutsson
2007-03-16 17:15 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) Bernd Petrovitsch
2007-03-16 23:20 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?) Jan Engelhardt
2007-03-17 0:59 ` Richard Knutsson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45FB3D74.2040907@student.ltu.se \
--to=ricknu-0@student.ltu.se \
--cc=acme@ghostprotocols.net \
--cc=jengelh@linux01.gwdg.de \
--cc=kernel-janitors@lists.osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox