[RFC] eal: use _Static_assert() for RTE_BUILD_BUG_ON
Tyler Retzlaff
roretzla at linux.microsoft.com
Mon Nov 13 17:30:17 CET 2023
On Sat, Nov 11, 2023 at 06:52:26PM +0100, Morten Brørup wrote:
> > From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> > Sent: Saturday, 11 November 2023 18.22
> >
> > The method of doing sizeof a bad array element was an interesting
> > hack but it has a couple of problems. First, it won't work if
> > VLA checking is enabled. It doesn't enforce that the expression
> > is constant.
> >
> > Replace that with the _Static_assert builtin available in
> > Gcc, Clang, and MSVC.
> >
> > Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> > ---
>
> Two souls, one thought...
> I have been considering exactly the same, and thus strongly support this.
>
> > -#define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 -
> > 2*!!(condition)]))
> > +#define RTE_BUILD_BUG_ON(e) _Static_assert(!(e), #e)
>
> Please use static_assert instead of _Static_assert, as discussed with Bruce:
>
> http://inbox.dpdk.org/dev/ZR%2FlDC88s+HYXw27@bricha3-MOBL.ger.corp.intel.com/
+1
At least in public headers use the macro static_assert for portability
with C++.
>
> Acked-by: Morten Brørup <mb at smartsharesystems.com>
one more time for good measure, this is an important change.
Acked-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
More information about the dev
mailing list