blob: 3119e1f809eb94d1c91fc5f2a0900d6e08d03578 [file] [log] [blame]
Dan Handleyf3c8f322014-04-17 17:29:58 +01001/*
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +01002 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
Dan Handleyf3c8f322014-04-17 17:29:58 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handleyf3c8f322014-04-17 17:29:58 +01005 */
6
7#ifndef __CASSERT_H__
8#define __CASSERT_H__
9
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010010#include <cdefs.h>
11
Dan Handleyf3c8f322014-04-17 17:29:58 +010012/*******************************************************************************
13 * Macro to flag a compile time assertion. It uses the preprocessor to generate
14 * an invalid C construct if 'cond' evaluates to false.
Sandrine Bailleux9fbf5e42015-10-14 16:00:23 +010015 * The following compilation error is triggered if the assertion fails:
Dan Handleyf3c8f322014-04-17 17:29:58 +010016 * "error: size of array 'msg' is negative"
Sandrine Bailleux9fbf5e42015-10-14 16:00:23 +010017 * The 'unused' attribute ensures that the unused typedef does not emit a
18 * compiler warning.
Dan Handleyf3c8f322014-04-17 17:29:58 +010019 ******************************************************************************/
Sandrine Bailleux9fbf5e42015-10-14 16:00:23 +010020#define CASSERT(cond, msg) \
Soren Brinkmann46dd1702016-01-14 10:11:05 -080021 typedef char msg[(cond) ? 1 : -1] __unused
Dan Handleyf3c8f322014-04-17 17:29:58 +010022
23#endif /* __CASSERT_H__ */