blob: 40cb483a8259e661a49815e900dffe2382a0ed8b [file] [log] [blame]
Dan Handleyf3c8f322014-04-17 17:29:58 +01001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
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
10/*******************************************************************************
11 * Macro to flag a compile time assertion. It uses the preprocessor to generate
12 * an invalid C construct if 'cond' evaluates to false.
Sandrine Bailleux9fbf5e42015-10-14 16:00:23 +010013 * The following compilation error is triggered if the assertion fails:
Dan Handleyf3c8f322014-04-17 17:29:58 +010014 * "error: size of array 'msg' is negative"
Sandrine Bailleux9fbf5e42015-10-14 16:00:23 +010015 * The 'unused' attribute ensures that the unused typedef does not emit a
16 * compiler warning.
Dan Handleyf3c8f322014-04-17 17:29:58 +010017 ******************************************************************************/
Sandrine Bailleux9fbf5e42015-10-14 16:00:23 +010018#define CASSERT(cond, msg) \
Soren Brinkmann46dd1702016-01-14 10:11:05 -080019 typedef char msg[(cond) ? 1 : -1] __unused
Dan Handleyf3c8f322014-04-17 17:29:58 +010020
21#endif /* __CASSERT_H__ */