From c4ba1c53edb2f59ebce5d8dfc92827820a318f0a Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 26 Aug 2015 16:10:35 +0200 Subject: [PATCH] core: added RIOT's own assert macro --- core/include/assert.h | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 core/include/assert.h diff --git a/core/include/assert.h b/core/include/assert.h new file mode 100644 index 000000000..80742fb5e --- /dev/null +++ b/core/include/assert.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 INRIA + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @addtogroup core_util + * + * @{ + * @file + * @brief POSIX.1-2008 compliant version of the assert macro + * + * @author Oliver Hahm + */ + +#ifndef ASSERT_H +#define ASSERT_H + +#include "panic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief abort the program if assertion is false + * + * If the macro NDEBUG was defined at the moment was last included, + * the macro assert() generates no code, and hence does nothing at all. + * + * Otherwise, the macro assert() prints an error message to standard error and + * terminates the application by calling core_panic(). + * + * The purpose of this macro is to help programmers find bugs in their + * programs. + */ + +#ifdef NDEBUG +#define assert(ignore)((void) 0) +#else +#define assert(cond) ((cond) ? (void)0 : core_panic(PANIC_ASSERT_FAIL, "assert")) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ASSERT_H */ +/** @} */