From 0ee46e8d4206084e6eca02c17168d68b92eb2806 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 23 May 2023 17:38:05 +0200 Subject: [PATCH] core/compiler_hints: add may_be_zero() --- core/lib/include/compiler_hints.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/lib/include/compiler_hints.h b/core/lib/include/compiler_hints.h index d300146fed..7d3bc8583f 100644 --- a/core/lib/include/compiler_hints.h +++ b/core/lib/include/compiler_hints.h @@ -181,6 +181,19 @@ extern "C" { #define assume(cond) assert(cond) #endif +/** + * @brief Wrapper function to silence "comparison is always false due to limited + * range of data type" type of warning when the warning is caused by a + * preprocessor configuration value that may be zero. + * + * @param[in] n Variable that may be zero + * @return The same variable @p n + */ +static inline unsigned may_be_zero(unsigned n) +{ + return n; +} + #ifdef __cplusplus } #endif