blob: bbfdfdb2ed944d5e519e298fd3669894ecc318ec [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
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef CASSERT_H
8#define CASSERT_H
Dan Handleyf3c8f322014-04-17 17:29:58 +01009
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
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000023#endif /* CASSERT_H */