[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wiPZmd1hrsUoP+9vPg2=E0Jj6Li77_BZcV9GocbJg8fag@mail.gmail.com>
Date: Thu, 14 Nov 2024 10:40:29 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Philipp Reisner <philipp.reisner@...bit.com>, Kees Cook <keescook@...omium.org>
Cc: Luc Van Oostenryck <luc.vanoostenryck@...il.com>, linux-sparse@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/1] compiler.h: Add missing include statement for build_bug.h
On Thu, 14 Nov 2024 at 10:28, Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> There's probably some trick I'm missing, but yeah, it looks like we
> need our BUILD_BUG_ON_ZERO() thing with that crazy bitfield hack.
.. and right after sending that, I figured out the trick.
You can use 'static_assert()' inside a type definition.
So the way to turn it into an expression is to just use the same
'sizeof(empty struct)' trick that we use for BUILD_BUG_ON_ZERO:
#define Static_assert(a,msg) \
sizeof(struct{_Static_assert(a,msg);})
works as a way to make _Static_assert() be an expression. What a horrid hack.
I don't know if this is worth it, but it does at least have the
advantage of having a message, so that the error case can explain
itself rather than get that odd
"negative width in bit-field"
error message.
I dunno.
Linus
Powered by blists - more mailing lists