Re: [PATCH 3/7] compiler.h: Add __if_constexpr(expr, if_const, if_not_const)

From: Linus Torvalds
Date: Wed Jul 24 2024 - 15:49:20 EST


On Wed, 24 Jul 2024 at 07:30, David Laight <David.Laight@xxxxxxxxxx> wrote:
>
> Implemented using _Generic() for portibility.

I do think this is ultimately the clearer implementation, if only
because the underlying trick it uses does very much depend on a very
special oddity in the C type system.

So then using the type comparison with _Generic() is rather natural,
and allows for picking other things than 0/1 as a result.

However, there is NO WAY this is a "portability" enhancement.

The original trick basically works on all ANSI C versions, while
"_Generic()" is quite a modern thing (added in C11? Something like
that)

Now, in the kernel we obviously already moved to -std=gnu11 a couple
of years ago, so doing this looks reasonable.

But what does not look reasonable to me is claiming that it's a
portability thing. Quite the opposite. It still requires the same
ternary operator type trick, now it just requires _Generic() support
in _addition_ to it.

Linus