Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1241221
| From | Michal Marek <mmarek@suse.cz> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/2] linux/kconfig.h: generalize IS_ENABLED logic |
| Date | 2015-10-07 10:20 +0200 |
| Message-ID | <qgS77-7ys-3@gated-at.bofh.it> (permalink) |
| References | <qgD87-2O1-69@gated-at.bofh.it> <qgHEK-11w-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 2015-10-06 23:05, Rasmus Villemoes wrote:
> It's not hard to generalize the macro magic used to build the
> IS_ENABLED macro and friends to produce a few other potentially useful
> macros:
>
> CHOOSE_EXPR(CONFIG_FOO, expr): if CONFIG_FOO is set expands to
> expr, otherwise expands to nothing.
>
> CHOOSE_EXPR(CONFIG_FOO, expr1, expr2): if CONFIG_FOO is set,
> expands to expr1, otherwise expands to expr2.
FWIW, I agree with Ingo that the CHOOSE_EXPR name is not really obvious.
IF_CONFIG is a better alternative IMO, since the average programmer
probably does not know __builtin_choose_expr() to see the analogy.
> Similarly, we can define helpers for conditional struct members and
> their associated initializers. It would probably take some time to get
> used to reading, to pick another random example,
>
> struct task_struct {
> ...
> COND_DECLARATION(CONFIG_KASAN, unsigned int kasan_depth)
> ...
> }
While the C standard syntax requires struct-declaration to actually
declare a member, the compiler will happily ignore the extra semicolon
if you write
truct task_struct {
...
CHOOSE_EXPR(CONFIG_KASAN, unsigned int kasan_depth);
...
}
So I think that the COND_DECLARATION macro is not necessary.
> #define INIT_KASAN(tsk) COND_INITIALIZER(CONFIG_KASAN, .kasan_depth = 1)
COND_INITIALIZER on the other hand is useful (CHOOSE_EXPR(CONFIG_KASAN,
.kasan_depth = 1 _COMMA) does does not work, unfortunately).
> [and I'm certainly not proposing any mass conversion], but I think it
> might be nice to avoid lots of short #ifdef/#else/#endif sections.
It should be accompanied by a patch to scripts/tags.sh teaching
ctags/etags about the new macros.
Michal
--
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/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/2] x86: dumpstack, use pr_cont Jiri Slaby <jslaby@suse.cz> - 2015-10-06 14:30 +0200
Re: [PATCH 1/2] x86: dumpstack, use pr_cont Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-10-06 18:10 +0200
Re: [PATCH 1/2] x86: dumpstack, use pr_cont Jiri Slaby <jslaby@suse.cz> - 2015-10-06 18:20 +0200
[PATCH 1/2] linux/kconfig.h: generalize IS_ENABLED logic Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-10-06 23:10 +0200
[PATCH 2/2] x86: dumpstack: eliminate some #ifdefs Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-10-06 23:10 +0200
Re: [PATCH 2/2] x86: dumpstack: eliminate some #ifdefs Ingo Molnar <mingo@kernel.org> - 2015-10-07 09:10 +0200
Re: [PATCH 1/2] linux/kconfig.h: generalize IS_ENABLED logic Ingo Molnar <mingo@kernel.org> - 2015-10-07 09:00 +0200
Re: [PATCH 1/2] linux/kconfig.h: generalize IS_ENABLED logic Michal Marek <mmarek@suse.cz> - 2015-10-07 10:20 +0200
Re: [PATCH 1/2] linux/kconfig.h: generalize IS_ENABLED logic Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-10-07 23:40 +0200
Re: [PATCH 1/2] linux/kconfig.h: generalize IS_ENABLED logic Michal Marek <mmarek@suse.cz> - 2015-10-08 13:50 +0200
csiph-web