在linux下,可以使用一些宏,加上自定义格式输出,让输出更易于调试:
排版出来可能有些乱,注意do{ }while(0);是在一行里就可以了。
- #include <stdio.h>
- #include <stdlib.h>
- #define DEBUG1( fmt, arg ... )
- do{printf("[DEBUG] " fmt , ##arg ); }while(0);
- #define DEBUG2( fmt, arg ... )
- do{printf("[%s: %s: line %d]" fmt ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor1( fmt, arg ... )
- do{printf(" 33[30m""[%s: %s: line %d]" fmt" 33[0m" ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor2( fmt, arg ... )
- do{printf(" 33[31m""[%s: %s: line %d]" fmt" 33[0m" ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor3( fmt, arg ... )
- do{printf(" 33[32m""[%s: %s: line %d]" fmt" 33[0m" ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor4( fmt, arg ... )
- do{printf(" 33[33m""[%s: %s: line %d]" fmt" 33[0m" ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor5( fmt, arg ... )
- do{printf(" 33[34m""[%s: %s: line %d]" fmt" 33[0m" ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor6( fmt, arg ... )
- do{printf(" 33[35m""[%s: %s: line %d]" fmt" 33[0m" ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor7( fmt, arg ... )
- do{printf(" 33[36m""[%s: %s: line %d]" fmt" 33[0m" ,
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- int main()
- {
- printf("I AM IN macro.c ");
- DEBUG1("I AM IN macro.c ");
- DEBUG2("I AM IN macro.c ");
- PrintColor1("I AM IN macro.c ");
- PrintColor2("I AM IN macro.c ");
- PrintColor3("I AM IN macro.c ");
- PrintColor4("I AM IN macro.c ");
- PrintColor5("I AM IN macro.c ");
- PrintColor6("I AM IN macro.c ");
- PrintColor7("I AM IN macro.c ");
- return 0;
- }
输出结果:
- http://blog.csdn.net/xiangpingli/article/details/7914133