Re: [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__

From: Thomas Weißschuh

Date: Fri Mar 20 2026 - 16:38:22 EST


On 2026-03-19 10:24:14+0000, David Laight wrote:
> On Wed, 18 Mar 2026 17:12:42 +0100
> Thomas Weißschuh <linux@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx>
> > ---
> > 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

That may break applications, so I'd rather not do it.

> > +
> > #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, "")
> >
>