Skip to content

Instantly share code, notes, and snippets.

@Luctins
Last active July 9, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luctins/91a7cbe5bad4c68684d3338bfde4f558 to your computer and use it in GitHub Desktop.
Save Luctins/91a7cbe5bad4c68684d3338bfde4f558 to your computer and use it in GitHub Desktop.
Pack of helper and debug macros for C
#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