[PATCH v3 5/5] eal: replace out of bounds VLA with static_assert
    Stephen Hemminger 
    stephen at networkplumber.org
       
    Wed Jan 17 18:11:36 CET 2024
    
    
  
On Wed, 17 Jan 2024 08:53:44 +0100
Mattias Rönnblom <hofors at lysator.liu.se> wrote:
> >    * Triggers an error at compilation time if the condition is true.
> >    */
> > -#define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
> > +#define RTE_BUILD_BUG_ON(condition) { static_assert(!(condition), #condition); }
> >   
> >   /*********** Cache line related macros ********/
> >     
> 
> Should one use RTE_BUILD_BUG_ON() or static_assert() in new DPDK code?
> 
> If static_assert() occasionally needs a work-around, it sounds like 
> keeping using RTE_BUILD_BUG_ON() everywhere is the better choice.
Either choice is the same. Keeping the macro instead of directly using
static_assert will reduce the effort to change when the next C standard
introduces something different.
But using static_assert() can allow for a better warning message.
    
    
More information about the dev
mailing list