xref: /arm-trusted-firmware/include/lib/cassert.h (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2014-2018, Arm Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #ifndef CASSERT_H
8*91f16700Schasinglulu #define CASSERT_H
9*91f16700Schasinglulu 
10*91f16700Schasinglulu #include <cdefs.h>
11*91f16700Schasinglulu 
12*91f16700Schasinglulu /*******************************************************************************
13*91f16700Schasinglulu  * Macro to flag a compile time assertion. It uses the preprocessor to generate
14*91f16700Schasinglulu  * an invalid C construct if 'cond' evaluates to false.
15*91f16700Schasinglulu  * The following compilation error is triggered if the assertion fails:
16*91f16700Schasinglulu  * "error: size of array 'msg' is negative"
17*91f16700Schasinglulu  * The 'unused' attribute ensures that the unused typedef does not emit a
18*91f16700Schasinglulu  * compiler warning.
19*91f16700Schasinglulu  ******************************************************************************/
20*91f16700Schasinglulu #define CASSERT(cond, msg)	\
21*91f16700Schasinglulu 	typedef char msg[(cond) ? 1 : -1] __unused
22*91f16700Schasinglulu 
23*91f16700Schasinglulu #endif /* CASSERT_H */
24