Debug macros for Linux C programming
In the process of completing the project, it is unavoidable to debug, here I give you a I am using a debug macro. Nonsense not much to say, directly on the code.
Implementation code
/*************************************************************************> File name:debug.c> Author:answer> Mail: [email protected]> Created time:2015 July 23 Thursday 18:19 48 seconds ************************************************************************/#include <stdio.h>#define Debug_print do{}while (0)#if defined (debug_print)#define DEBUG (...) \do{\fprintf (stderr, "-----DEBUG-----\ n");fprintf (stderr, "%s%s\n", __time__,__date__); \fprintf (stderr, "%s:%d:%s ():", __file__,__line__,__func__);fprintf (stderr,__va_args__); \}while (0)#endifint main (void) {Debug ("Debug successfully!\n");return 0;}
Description
1. Do{}while (0): use do{...} while (0) the constructed macro definition is not affected by curly braces, semicolons, and so on, and you can define an empty macro without being warned.
2. Parameter Description:
__LINE____FILE____DATE____TIME____func__:输出函数名称,功能与_Function___VA_ARGS__:可变参数类型。
Note: The specific code can be found in https://github.com/AnSwErYWJ/DogFood/blob/master/debug.c.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Debug macros for Linux C programming