Difference between revisions of "C programming/Debug"
From Teknologisk videncenter
m (added Category:C using HotCat) |
m |
||
Line 19: | Line 19: | ||
Compile and run | Compile and run | ||
− | <source lang= | + | <source lang=bash> |
[root@oldmars bin]#gcc debug.c -o debug | [root@oldmars bin]#gcc debug.c -o debug | ||
[root@oldmars bin]#./debug | [root@oldmars bin]#./debug |
Latest revision as of 16:01, 24 November 2020
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