simple logging in C programming
#include
#undef PDEBUG /* undef it, just in case */
#ifdef SCULL_DEBUG
# define PDEBUG(fmt, args…) printf(”[%s-%s:%d]-[Debug] ” fmt “\n”, __FILE__, __func__, __LINE__, ## args)
#else
# define PDEBUG(fmt, args…) /* not debugging: nothing */
#endif
int main(void)
{
char * val = “wifihack.net”;
PDEBUG(”Hello, %s”, val);
return 0;
}
[/code]
为了减少修改头文件,我们可以通过Makefile来控制Debug信息的输出:
[code lang="c"]
# Comment/uncomment the following line to disable/enable debugging
DEBUG = y
# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DSCULL_DEBUG # “-O” is needed to expand inlines
else
DEBFLAGS = -O2
endif
CFLAGS += $(DEBFLAGS)
ALL:
gcc $(CFLAGS) -o hello hello.c
[/code]
参考: http://www.makelinux.net/ldd3/chp-4-sect-2.shtml
–
Bian Jiang
Recent Comments