Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 93c78ed | 2018-08-16 16:52:57 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __CASSERT_H__ |
| 8 | #define __CASSERT_H__ |
| 9 | |
Antonio Nino Diaz | 93c78ed | 2018-08-16 16:52:57 +0100 | [diff] [blame^] | 10 | #include <cdefs.h> |
| 11 | |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 12 | /******************************************************************************* |
| 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 Bailleux | c17a4dc | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 15 | * The following compilation error is triggered if the assertion fails: |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 16 | * "error: size of array 'msg' is negative" |
Sandrine Bailleux | c17a4dc | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 17 | * The 'unused' attribute ensures that the unused typedef does not emit a |
| 18 | * compiler warning. |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 19 | ******************************************************************************/ |
Sandrine Bailleux | c17a4dc | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 20 | #define CASSERT(cond, msg) \ |
Soren Brinkmann | 65cd299 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 21 | typedef char msg[(cond) ? 1 : -1] __unused |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 22 | |
| 23 | #endif /* __CASSERT_H__ */ |