public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Willy Tarreau <w@1wt.eu>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__
Date: Thu, 19 Mar 2026 10:24:14 +0000	[thread overview]
Message-ID: <20260319102414.4c44de3f@pumpkin> (raw)
In-Reply-To: <20260318-nolibc-wundef-v1-1-fcb7f9ac7298@weissschuh.net>

On Wed, 18 Mar 2026 17:12:42 +0100
Thomas Weißschuh <linux@weissschuh.net> wrote:

> With -std=c89 the macro __STDC_VERSION__ is not defined.
> While undefined identifiers in '#if' directives are assumed to be '0',
> with -Wundef a warning is emitted.
> 
> Avoid the warning by explicitly falling back to '0' if __STDC_VERSION__
> is not provided by the preprocessor.
> 
> Fixes: 37219aa5b123 ("tools/nolibc: add __nolibc_static_assert()")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
>  tools/include/nolibc/compiler.h | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h
> index f03f84cfadce..dac09badff0a 100644
> --- a/tools/include/nolibc/compiler.h
> +++ b/tools/include/nolibc/compiler.h
> @@ -47,6 +47,12 @@
>  #  define __nolibc_fallthrough do { } while (0)
>  #endif /* __nolibc_has_attribute(fallthrough) */
>  
> +#ifdef __STDC_VERSION__
> +#  define __nolibc_stdc_version __STDC_VERSION__
> +#else
> +#  define __nolibc_stdc_version 0
> +#endif

How about:
#ifndef __STDC_VERSION__
#define __STDC_VERSION__ 198900
#endif

	David

> +
>  #define __nolibc_version(_major, _minor, _patch) ((_major) * 10000 + (_minor) * 100 + (_patch))
>  
>  #ifdef __GNUC__
> @@ -63,7 +69,7 @@
>  #  define __nolibc_clang_version 0
>  #endif /* __clang__ */
>  
> -#if __STDC_VERSION__ >= 201112L || \
> +#if __nolibc_stdc_version >= 201112L || \
>  	__nolibc_gnuc_version >= __nolibc_version(4, 6, 0) || \
>  	__nolibc_clang_version >= __nolibc_version(3, 0, 0)
>  #  define __nolibc_static_assert(_t) _Static_assert(_t, "")
> 


  reply	other threads:[~2026-03-19 10:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18 16:12 [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Thomas Weißschuh
2026-03-18 16:12 ` [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ Thomas Weißschuh
2026-03-19 10:24   ` David Laight [this message]
2026-03-20 20:38     ` Thomas Weißschuh
2026-03-18 16:12 ` [PATCH 2/2] selftests/nolibc: enable -Wundef Thomas Weißschuh
2026-03-22  8:40 ` [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Willy Tarreau

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=20260319102414.4c44de3f@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=w@1wt.eu \
    /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