From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] include: is_defined: implement __if_defined helper
Date: Wed, 3 Apr 2024 09:23:32 +0200 [thread overview]
Message-ID: <20240403072332.2694292-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240403072332.2694292-1-a.fatoum@pengutronix.de>
This is useful when preprocessing non-C code that lacks an if statement
equivalent. For example, external device tree fragments can now specify:
#include <linux/is_defined.h>
__if_defined(bcm2711_rpi_4_dts, &emmc2, &sdhost) {
instead of having to use the more verbose #ifdef:
#ifdef bcm2711_rpi_4_dts
&emmc2 {
#else
&sdhost {
#endif
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/is_defined.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/is_defined.h b/include/linux/is_defined.h
index d68f8e877f9b..bfefca033f70 100644
--- a/include/linux/is_defined.h
+++ b/include/linux/is_defined.h
@@ -34,4 +34,10 @@
#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val)
#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0)
+#define __if_defined(x, a, b) ___if_defined(__is_defined(x), a, b)
+#define ___if_defined(val, a, b) ____if_defined(val, a, b)
+#define ____if_defined(val, a, b) ____if_defined_##val(a, b)
+#define ____if_defined_1(a, b) a
+#define ____if_defined_0(a, b) b
+
#endif
--
2.39.2
next prev parent reply other threads:[~2024-04-03 7:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 7:23 [PATCH 1/2] include: kconfig.h: move __is_defined definition into new header Ahmad Fatoum
2024-04-03 7:23 ` Ahmad Fatoum [this message]
2024-04-22 12:16 ` Sascha Hauer
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=20240403072332.2694292-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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