C programming/Debug
From Teknologisk videncenter
Simple
#include <stdio.h>
// debugging macros so we can pin down message origin at a glance
#define WHERESTR "[file %s, line %d]: "
#define WHEREARG __FILE__, __LINE__
#define DEBUGPRINT2(...) fprintf(stderr, __VA_ARGS__)
#define DEBUGPRINT(_fmt, ...) DEBUGPRINT2(WHERESTR _fmt, WHEREARG, __VA_ARGS__)
//...
int main(main) {
int x = 9;
printf("Real code....\n");
DEBUGPRINT("I am a debug string...., x=%d\n", x);
printf("Done\n");
return(0);
}
Compile and run
[root@oldmars bin]#gcc debug.c -o debug
[root@oldmars bin]#./debug
Real code....
[file debug.c, line 13]: I am a debug string...., x=9
Done