Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. |
| 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 | |
| 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 Bailleux | c17a4dc | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 13 | * The following compilation error is triggered if the assertion fails: |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 14 | * "error: size of array 'msg' is negative" |
Sandrine Bailleux | c17a4dc | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 15 | * The 'unused' attribute ensures that the unused typedef does not emit a |
| 16 | * compiler warning. |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 17 | ******************************************************************************/ |
Sandrine Bailleux | c17a4dc | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 18 | #define CASSERT(cond, msg) \ |
Soren Brinkmann | 65cd299 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 19 | typedef char msg[(cond) ? 1 : -1] __unused |
Dan Handley | bdbfc3c | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 20 | |
| 21 | #endif /* __CASSERT_H__ */ |