From: Alejandro Colomar <alx@kernel.org>
To: Kees Cook <kees@kernel.org>, linux-hardening@vger.kernel.org
Cc: Andy Shevchenko <andy@kernel.org>
Subject: Re: [PATCH v1 1/2] args: Add DEFARG() to implement macro default arguments
Date: Tue, 3 Nov 2026 14:31:43 +0100 [thread overview]
Message-ID: <auniCwwVW4AjWkIB@devuan> (raw)
In-Reply-To: <be1057524eb2d7bb378d205c3fc8074acbf124e2.1793712214.git.alx@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 1647 bytes --]
> Date: 2026-11-03 14:27:11+0100
> From: Alejandro Colomar <alx@kernel.org>
>
> It needs __VA_OPT__, which is a C23 feature, but it's provided by GCC
> and Clang in GNU-C mode as an extension even without C23. __VA_OPT__
> was implemented in GCC 9 and Clang 6, I think, so it should be widely
Actually, it seems it was implemented in Clang 12, not Clang 6.
I got that 6 from llvmorg-6.0.0-rc1, but that version number seems to
not be the same as the Clang version number. Anyway, Clang 12 should be
fine, I think.
Cheers,
Alex
> available.
>
> Here's a small example program showing how this works:
>
> alx@devuan:~/tmp$ cat d.c
> #define D__(x, ...) (x)
> #define D_(x, ...) D__(__VA_ARGS__ __VA_OPT__(,) x)
> #define D(a, b) D_(a, b)
> D(1, 2)
> D(1, )
> D(, 2)
> D(,)
> alx@devuan:~/tmp$ gcc -E -Wall -Wextra d.c | grep '^[^#]'
> (2)
> (1)
> (2)
> ()
>
> Signed-off-by: Alejandro Colomar <alx@kernel.org>
> ---
> include/linux/args.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/include/linux/args.h b/include/linux/args.h
> index 0562dc51435e..5886011cf791 100644
> --- a/include/linux/args.h
> +++ b/include/linux/args.h
> @@ -3,6 +3,11 @@
> #ifndef _LINUX_ARGS_H
> #define _LINUX_ARGS_H
>
> +/* Expand to 'arg' if non-empty, or to 'def' if 'arg' is empty. */
> +#define ___DEFARG(x, ...) (x)
> +#define __DEFARG(def, ...) ___DEFARG(__VA_ARGS__ __VA_OPT__(,) def)
> +#define DEFARG(def, arg) __DEFARG(def, arg)
> +
> /*
> * How do these macros work?
> *
> --
> 2.55.0
>
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-11-03 13:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 13:27 [PATCH v1 0/2] Simplify implementation of strscpy() Alejandro Colomar
2026-11-03 13:27 ` [PATCH v1 1/2] args: Add DEFARG() to implement macro default arguments Alejandro Colomar
2026-11-03 13:31 ` Alejandro Colomar [this message]
2026-11-03 13:27 ` [PATCH v1 2/2] string: Simplify strscpy[_pad]() Alejandro Colomar
2026-11-03 19:10 ` [PATCH v1 0/2] Simplify implementation of strscpy() Andy Shevchenko
2026-11-03 23:21 ` Alejandro Colomar
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=auniCwwVW4AjWkIB@devuan \
--to=alx@kernel.org \
--cc=andy@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@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