Function to fail at build time?

Morten Brørup mb at smartsharesystems.com
Thu Jun 26 17:23:40 CEST 2025


> From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> Sent: Thursday, 26 June 2025 16.32
> 
> On Thu, 26 Jun 2025 01:55:02 +0200
> Morten Brørup <mb at smartsharesystems.com> wrote:
> 
> > I was wondering if this was somehow possible:
> >
> > #define RTE_VERIFY(exp) do { \
> > +	if (__rte_constant(exp)) \
> > +		FAIL_AT_BUILD_TIME(); \
> > 	if (unlikely(!(exp))) \
> > 		rte_panic("line %d\tassert \"%s\" failed\n", __LINE__,
> #exp); \
> > } while (0)
> >
> > I tried static_assert(), but it cannot be used in this way.
> 
> 
> What happens?

The compiler says:
error: expected expression before '_Static_assert'

It seems static_assert is a declaration, so you cannot treat it as a function, using e.g.:
if (1) static_assert(1, "OK");




More information about the dev mailing list