* Function to fail at build time?
@ 2025-06-25 23:55 Morten Brørup
2025-06-26 14:31 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Morten Brørup @ 2025-06-25 23:55 UTC (permalink / raw)
To: dev
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.
-Morten
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Function to fail at build time?
2025-06-25 23:55 Function to fail at build time? Morten Brørup
@ 2025-06-26 14:31 ` Stephen Hemminger
2025-06-26 15:23 ` Morten Brørup
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2025-06-26 14:31 UTC (permalink / raw)
To: Morten Brørup; +Cc: dev
On Thu, 26 Jun 2025 01:55:02 +0200
Morten Brørup <mb@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?
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: Function to fail at build time?
2025-06-26 14:31 ` Stephen Hemminger
@ 2025-06-26 15:23 ` Morten Brørup
0 siblings, 0 replies; 3+ messages in thread
From: Morten Brørup @ 2025-06-26 15:23 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Thursday, 26 June 2025 16.32
>
> On Thu, 26 Jun 2025 01:55:02 +0200
> Morten Brørup <mb@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");
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-26 15:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-25 23:55 Function to fail at build time? Morten Brørup
2025-06-26 14:31 ` Stephen Hemminger
2025-06-26 15:23 ` Morten Brørup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).