xref: /rk3399_ARM-atf/include/lib/cassert.h (revision c17a4dc34c0aa449e843595319fd9380c2a753b4)
1bdbfc3c2SDan Handley /*
2bdbfc3c2SDan Handley  * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3bdbfc3c2SDan Handley  *
4bdbfc3c2SDan Handley  * Redistribution and use in source and binary forms, with or without
5bdbfc3c2SDan Handley  * modification, are permitted provided that the following conditions are met:
6bdbfc3c2SDan Handley  *
7bdbfc3c2SDan Handley  * Redistributions of source code must retain the above copyright notice, this
8bdbfc3c2SDan Handley  * list of conditions and the following disclaimer.
9bdbfc3c2SDan Handley  *
10bdbfc3c2SDan Handley  * Redistributions in binary form must reproduce the above copyright notice,
11bdbfc3c2SDan Handley  * this list of conditions and the following disclaimer in the documentation
12bdbfc3c2SDan Handley  * and/or other materials provided with the distribution.
13bdbfc3c2SDan Handley  *
14bdbfc3c2SDan Handley  * Neither the name of ARM nor the names of its contributors may be used
15bdbfc3c2SDan Handley  * to endorse or promote products derived from this software without specific
16bdbfc3c2SDan Handley  * prior written permission.
17bdbfc3c2SDan Handley  *
18bdbfc3c2SDan Handley  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19bdbfc3c2SDan Handley  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20bdbfc3c2SDan Handley  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21bdbfc3c2SDan Handley  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22bdbfc3c2SDan Handley  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23bdbfc3c2SDan Handley  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24bdbfc3c2SDan Handley  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25bdbfc3c2SDan Handley  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26bdbfc3c2SDan Handley  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27bdbfc3c2SDan Handley  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28bdbfc3c2SDan Handley  * POSSIBILITY OF SUCH DAMAGE.
29bdbfc3c2SDan Handley  */
30bdbfc3c2SDan Handley 
31bdbfc3c2SDan Handley #ifndef __CASSERT_H__
32bdbfc3c2SDan Handley #define __CASSERT_H__
33bdbfc3c2SDan Handley 
34bdbfc3c2SDan Handley /*******************************************************************************
35bdbfc3c2SDan Handley  * Macro to flag a compile time assertion. It uses the preprocessor to generate
36bdbfc3c2SDan Handley  * an invalid C construct if 'cond' evaluates to false.
37bdbfc3c2SDan Handley  * The following compilation error is triggered if the assertion fails:
38bdbfc3c2SDan Handley  * "error: size of array 'msg' is negative"
39*c17a4dc3SSandrine Bailleux  * The 'unused' attribute ensures that the unused typedef does not emit a
40*c17a4dc3SSandrine Bailleux  * compiler warning.
41bdbfc3c2SDan Handley  ******************************************************************************/
42*c17a4dc3SSandrine Bailleux #define CASSERT(cond, msg)	\
43*c17a4dc3SSandrine Bailleux 	typedef char msg[(cond) ? 1 : -1] __attribute__((unused))
44bdbfc3c2SDan Handley 
45bdbfc3c2SDan Handley #endif /* __CASSERT_H__ */
46