Dan Handley | f3c8f32 | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. |
Dan Handley | f3c8f32 | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | f3c8f32 | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef CASSERT_H |
| 8 | #define CASSERT_H |
Dan Handley | f3c8f32 | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 9 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 10 | #include <cdefs.h> |
| 11 | |
Dan Handley | f3c8f32 | 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 | 9fbf5e4 | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 15 | * The following compilation error is triggered if the assertion fails: |
Dan Handley | f3c8f32 | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 16 | * "error: size of array 'msg' is negative" |
Sandrine Bailleux | 9fbf5e4 | 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 | f3c8f32 | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 19 | ******************************************************************************/ |
Sandrine Bailleux | 9fbf5e4 | 2015-10-14 16:00:23 +0100 | [diff] [blame] | 20 | #define CASSERT(cond, msg) \ |
Soren Brinkmann | 46dd170 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 21 | typedef char msg[(cond) ? 1 : -1] __unused |
Dan Handley | f3c8f32 | 2014-04-17 17:29:58 +0100 | [diff] [blame] | 22 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 23 | #endif /* CASSERT_H */ |