Skip to content

Instantly share code, notes, and snippets.

@hraftery
Created February 1, 2024 23:18
Show Gist options
  • Save hraftery/9d83f94d3bda8b5ce33b4cabf8ccf696 to your computer and use it in GitHub Desktop.
Save hraftery/9d83f94d3bda8b5ce33b4cabf8ccf696 to your computer and use it in GitHub Desktop.
System-wide assert routines to suit embedded programming
/**
* \file
*
* \brief Common assert functionality to suit embedded development.
*
* \author Heath Raftery
* \date March 2020
*/
#ifndef ASSERT_H_
#define ASSERT_H_
#include "error.h"
//Implement our own ASSERT macro
#define ASSERT(expr) ((expr) ? (void)0 : error_fatal(fseAssert, __FILE__, __LINE__)) //suits STM32
#define ASSERT(expr) ((expr) ? (void)0 : assert_failed_handler(__FILE__, __LINE__, __func__, #expr)) //suits Zephyr
//An assert that can be used at compile time
#define STATIC_ASSERT(expr,msg) typedef char static_assertion_##msg[(expr)?1:-1]
#endif /* ASSERT_H_ */
//prototype of handler, for reference
//void assert_failed_handler(const char *file, int line, const char *func, const char *expr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment