Skip to content

Instantly share code, notes, and snippets.

@fclairamb
Created September 3, 2013 16:42
Show Gist options
  • Save fclairamb/6426374 to your computer and use it in GitHub Desktop.
Save fclairamb/6426374 to your computer and use it in GitHub Desktop.
An evil way to test debug macro: ./debug.c BEGIN! ./debug.c:main:19: test! ./debug.c:main:20: test! END ! BEGIN! END !
#ifdef SHELL
gcc $0 && ./a.out
gcc -DNDEBUG $0 && ./a.out
exit 0
#endif
#include <stdio.h>
#ifndef NDEBUG
#define DEBUG(fmt, arg...) \
fprintf(stderr, __FILE__ ":%s:%d: " fmt,__FUNCTION__,__LINE__,##arg)
#else
#define DEBUG(fmt, args...)
#endif
int main( int argc, char * argv [] ) {
printf("BEGIN!\n");
DEBUG("test!\n");
DEBUG("%s", "test!\n");
printf("END !\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment