From: Steven Fuerst <sfuerst@stanford.edu>
To: linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] kconfig: introduce KCONFIG_* symbols for .c files
Date: Sat, 24 May 2008 16:36:22 -0700 [thread overview]
Message-ID: <200805241636.22242.sfuerst@stanford.edu> (raw)
> On Sat, May 24, 2008 at 09:58:47PM +0100, Jeremy Fitzhardinge wrote:
> >
> > Would
> >
> > #define KCONFIG(x) (CONFIG_##x - 0)
> >
> > if (KCONFIG(PREEMPT)) {
> > ...
> > }
> >
> > work?
>
> $ cat test.c
> #define KCONFIG(x) (CONFIG_##x - 0)
>
> int main()
> {
> if (KCONFIG(PREEMPT))
> ;
>
> return 0;
> }
> $ gcc -O2 -Wall test.c
> test.c: In function âmainâ:
> test.c:5: error: âCONFIG_PREEMPTâ undeclared (first use in this function)
> test.c:5: error: (Each undeclared identifier is reported only once
> test.c:5: error: for each function it appears in.)
> $ gcc --version
> gcc (Debian 4.3.0-5) 4.3.1 20080523 (prerelease)
>
> > J
>
> cu
> Adrian
How about this?
#include <stdio.h>
#define CONFIG_FOO 1
/* #define CONFIG_BAR 1 */
#define STR2(x) #x
#define STR(x) STR2(x)
#define PASTE2(x, y) x##y
#define PASTE(x, y) PASTE2(x, y)
#define KCONFIG2(x, y) STR(PASTE(CONFIG_, x))[y]
#define KCONFIG(x) (!((KCONFIG2(x, 0) == 'C') && \
(KCONFIG2(x, 1) == 'O') && \
(KCONFIG2(x, 2) == 'N') && \
(KCONFIG2(x, 3) == 'F') && \
(KCONFIG2(x, 4) == 'I') && \
(KCONFIG2(x, 5) == 'G') && \
(KCONFIG2(x, 6) == '_')))
int main()
{
if (KCONFIG(FOO)) printf("FOO\n");
if (KCONFIG(BAR)) printf("BAR\n");
return 0;
}
It of course assumes that the result of all defined macros you want to test
for do not start with "CONFIG_", so this doesn't work generally. However,
nearly all of the time the arguement to KCONFIG() will be defined to be "1"
an integer, or some other known string that doesn't begin with "CONFIG_", so
this trick is fairly robust.
Steven
next reply other threads:[~2008-05-24 23:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-24 23:36 Steven Fuerst [this message]
2008-05-25 0:00 ` Tom Spink
2008-05-25 0:20 ` Steven Fuerst
-- strict thread matches above, loose matches on Subject: below --
2008-05-24 19:25 Sam Ravnborg
2008-05-24 19:53 ` Andrew Morton
2008-05-24 20:14 ` Jeremy Fitzhardinge
2008-05-24 20:46 ` Sam Ravnborg
2008-05-24 20:56 ` Jeremy Fitzhardinge
2008-05-24 21:03 ` Sam Ravnborg
2008-05-24 20:24 ` Sam Ravnborg
2008-05-24 20:48 ` Andrew Morton
2008-05-24 21:00 ` Sam Ravnborg
2008-05-24 20:05 ` Adrian Bunk
2008-05-24 20:44 ` Sam Ravnborg
2008-05-24 20:57 ` Adrian Bunk
2008-05-24 20:20 ` Linus Torvalds
2008-05-24 20:48 ` Jeremy Fitzhardinge
2008-05-24 20:58 ` Jeremy Fitzhardinge
2008-05-24 21:03 ` Adrian Bunk
2008-05-24 21:13 ` Jeremy Fitzhardinge
2008-05-24 21:26 ` Pavel Machek
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=200805241636.22242.sfuerst@stanford.edu \
--to=sfuerst@stanford.edu \
--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
all inboxes | Powered by JetHome®