Last active
July 9, 2019 17:45
-
-
Save Luctins/91a7cbe5bad4c68684d3338bfde4f558 to your computer and use it in GitHub Desktop.
Pack of helper and debug macros for C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DEBUG_HELPER_H | |
#define DEBUG_HELPER_H | |
/** | |
@file debug_helper.h | |
@author Lucas Martins Mendes | |
@brief debug macros | |
*/ | |
/*--Used to paste tokens together--*/ | |
#define _TOKENPASTE(a,b,c) a ## b ## c | |
#define TOKENPASTE(a,b,c) _TOKENPASTE(a,b,c) | |
#define DEBUG_OUTPUT_F <your printf here> | |
#define DEBUG_OUTPUT <your puts here> | |
#define DEBUG(msg) \ | |
DEBUG_OUTPUT(msg); \ | |
DEBUG_OUTPUT("\n") | |
#define DEBUGF(msg,...) \ | |
DEBUG_OUTPUT_F(msg, __VA_ARGS__ ); \ | |
DEBUG_OUTPUT("\n") | |
#define DEBUG_NUM(str,number) \ | |
DEBUG_OUTPUT(str); \ | |
print_num(number); \ | |
DEBUG_OUTPUT("\n") | |
#define VAR_DUMP(var,fmt) \ | |
DEBUG_OUTPUT_F(#var":"fmt,var); \ | |
DEBUG_OUTPUT("\n"); | |
#define _STR(x) #x | |
#define STR(x) _STR(x) | |
#define ASSERT(cond) \ | |
if(!(cond)) \ | |
{ \ | |
} \ | |
else \ | |
{ \ | |
DEBUG_OUTPUT("error: \""STR(cond)"\" at "STR(__LINE__)); \ | |
} | |
#define ASSERT_ERROR(cond,do_err) \ | |
if(!(cond)) \ | |
{ \ | |
} \ | |
else \ | |
{ \ | |
DEBUG_OUTPUT("error:\""STR(cond)"\" at "STR(__LINE__)); \ | |
do_err; \ | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment