Skip to content

Instantly share code, notes, and snippets.

@ninux
Last active August 29, 2015 14:08
Show Gist options
  • Save ninux/75737af00635d9512164 to your computer and use it in GitHub Desktop.
Save ninux/75737af00635d9512164 to your computer and use it in GitHub Desktop.
debug messages in c
#ifdef DEBUG
#define _dbgmsg(MESSAGE, ...) printf("DEBUG: " #MESSAGE "\n", \
##__VA_ARGS__)
#else
#define _dbgmsg(MESSAGE) {}
#endif
@gandro
Copy link

gandro commented Oct 25, 2014

include <stdio.h>

#define DEBUG

#ifdef DEBUG
#define _dbgmsg(MESSAGE, ...) printf("DEBUG: " MESSAGE "\n", __VA_ARGS__)
#else
#define _dbgmsg(MESSAGE, ...) do {} while(0)
#endif

int main() {
    _dbgmsg("answer: %d", 42);

    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment