ic-macros  0.1.5
assert_constant.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, Intercreate, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 
8 #pragma once
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include "zephyr/build_assert.h"
15 
16 
22 #define IC_ASSERT_CONSTANT(expr) \
23  IC_BUILD_ASSERT(__builtin_constant_p(expr), #expr " is not a compile-time constant.")
24 
31 #define IC_REQUIRE_CONSTANT(expr) \
32  ({ \
33  IC_ASSERT_CONSTANT(expr); \
34  expr; \
35  })
36 
42 #define IC_ASSERT_NOT_CONSTANT(expr) \
43  IC_BUILD_ASSERT(!__builtin_constant_p(expr), #expr " is a compile-time constant.")
44 
51 #define IC_REQUIRE_NOT_CONSTANT(expr) \
52  ({ \
53  IC_ASSERT_NOT_CONSTANT(expr); \
54  expr; \
55  })
56 
57 #ifdef __cplusplus
58 }
59 #endif