xref: /rk3399_ARM-atf/drivers/ti/common/include/ti_build_assert.h (revision a28114d66a6d43db4accef5fd5d6dab6c059e584)
1 /*
2  * Copyright (c) 2025-2026 Texas Instruments Incorporated - https://www.ti.com
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*
8  * Build-Time Assertions
9  *
10  * This header provides a macro for performing compile-time assertions and
11  * validation of constant expressions during the build process.
12  */
13 
14 #ifndef TI_BUILD_ASSERT_H
15 #define TI_BUILD_ASSERT_H
16 
17 /*
18  * Compile-time assertion that evaluates to zero
19  *
20  * Similar to CASSERT (include/lib/cassert.h) but differs in that it evaluates
21  * to zero, making it usable inline within expressions. CASSERT generates a
22  * typedef statement and cannot be used inside an expression.
23  *
24  * If the condition is false, the array has negative size causing a compilation
25  * error. If true, evaluates to zero (sizeof(char[1]) - 1). Useful in macro
26  * expressions where a build-time check is needed without affecting the value.
27  */
28 #define TI_BUILD_ASSERT_OR_ZERO(cond) \
29 	(sizeof(char[(cond) ? 1 : -1]) - 1)
30 
31 #endif /* TI_BUILD_ASSERT_H */
32