2 * @brief General purpose macros.
14 extern int switch_alloc;
16 #define model_print(fmt, ...) do { \
18 char mprintbuf[256]; \
19 int printbuflen=snprintf_(mprintbuf, 256, fmt, ## __VA_ARGS__); \
20 int lenleft = printbuflen < 256 ?printbuflen:256; \
21 int totalwritten = 0;\
23 int byteswritten=write(model_out, &mprintbuf[totalwritten], lenleft);\
24 lenleft-=byteswritten; \
25 totalwritten+=byteswritten; \
31 #define DEBUG(fmt, ...) do { model_print("*** %15s:%-4d %25s() *** " fmt, __FILE__, __LINE__, __func__, ## __VA_ARGS__); } while (0)
32 #define DBG() DEBUG("\n")
33 #define DBG_ENABLED() (1)
35 #define DEBUG(fmt, ...)
37 #define DBG_ENABLED() (0)
40 void assert_hook(void);
43 #define ASSERT(expr) \
46 fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
47 /* print_trace(); // Trace printing may cause dynamic memory allocation */ \
49 _Exit(EXIT_FAILURE); \
53 #define ASSERT(expr) \
55 #endif /* CONFIG_ASSERT */
57 #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__)
59 void print_trace(void);
60 #endif /* __COMMON_H__ */