All of lore.kernel.org
 help / color / mirror / Atom feed
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: [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of
Date: Sat, 17 Mar 2007 00:59:32 +0000	[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


_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

WARNING: multiple messages have this Message-ID (diff)
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



  reply	other threads:[~2007-03-17  0:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-15 14:08 [KJ] [RFC] A need for a "yesno"-function? Richard Knutsson
2007-03-16  3:36 ` Arnaldo Carvalho de Melo
2007-03-16 15:24   ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) Richard Knutsson
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     ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Bernd Petrovitsch
2007-03-16 16:33       ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?) Bernd Petrovitsch
2007-03-16 17:09       ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Richard Knutsson
2007-03-16 17:09         ` [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 17:15         ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Bernd Petrovitsch
2007-03-16 17:15           ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) Bernd Petrovitsch
2007-03-16 23:20     ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Jan Engelhardt
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]
2007-03-17  0:59         ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) Richard Knutsson

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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.