From: "Tom Spink" <tspink@gmail.com>
To: "Steven Fuerst" <sfuerst@stanford.edu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] kconfig: introduce KCONFIG_* symbols for .c files
Date: Sun, 25 May 2008 01:00:51 +0100 [thread overview]
Message-ID: <7b9198260805241700o2bc38848m60d5853b63e6ff26@mail.gmail.com> (raw)
In-Reply-To: <200805241636.22242.sfuerst@stanford.edu>
2008/5/25 Steven Fuerst <sfuerst@stanford.edu>:
>
>> 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.
I've seen worse abuse of the preprocessor[1]. ;-)
> Steven
--
Tom Spink
[1] http://www.ioccc.org/
next prev parent reply other threads:[~2008-05-25 0:01 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-24 23:36 Steven Fuerst
2008-05-25 0:00 ` Tom Spink [this message]
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=7b9198260805241700o2bc38848m60d5853b63e6ff26@mail.gmail.com \
--to=tspink@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sfuerst@stanford.edu \
/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®