Debug macros for Linux C programming

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.