c++/c DEBUG宏

#cat log_debug.h
#ifdef DEBUG
int log_debug(const char *format, ...);
#else
int log_debug(const char *format, ...);
#endif
#cat log_debug.cc

#include <stdio.h>
#include <stdarg.h>
#ifdef DEBUG
void log_debug(const char *format, ...)
{
	printf("DEBUG
");

    va_list argPtr;
    int     count;

    va_start(argPtr, format);
    fflush(stdout);
    count = vfprintf(stderr, format, argPtr);
    va_end(argPtr);
}
#else
int log_debug(const char *format, ...)
{

}
#endif
#cat main.cc
#include <stdio.h>
#include "log_debug.h"

int main()
{
	printf("main
");
	log_debug("hello");
	return 0;
}

build: 打开宏开关的方式: -DDEBUG

#g++ -DDEBUG  log_debug.h log_debug.cc main.cc -o a
原文地址:https://www.cnblogs.com/muahao/p/8795427.html