原文地址: http://oopweb.com/CPP/Documents/DebugCPP/Volume/techniques.html
这一部分介绍调试技术,包含了从阅读手册到使用工具的相关信息。
GCC 部分 http://oopweb.com/CPP/Documents/DebugCPP/Volume/techniques.html
#ifndef DEBUG_H #define DEBUG_H #include <stdarg.h> #if defined(NDEBUG) && defined(__GNUC__) /* gcc‘s cpp has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away. */ #define pmesg(level, format, args...) ((void)0) #else void pmesg(int level, char *format, ...); /* print a message, if it is considered significant enough. Adapted from [K&R2], p. 174 */ #endif #endif /* DEBUG_H */ File debug.c: #include "debug.h" #include <stdio.h> extern int msglevel; /* the higher, the more messages... */ #if defined(NDEBUG) && defined(__GNUC__) /* Nothing. pmesg has been "defined away" in debug.h already. */ #else void pmesg(int level, char* format, ...) { #ifdef NDEBUG /* Empty body, so a good compiler will optimise calls to pmesg away */ #else va_list args; if (level>msglevel) return; va_start(args, format); vfprintf(stderr, format, args); va_end(args); #endif /* NDEBUG */ #endif /* NDEBUG && __GNUC__ */ }
原文:http://www.cnblogs.com/ridox/p/4365053.html