__FILE__,__LINE__ Output Debugging Information

Source: Internet
Author: User

At the time of writing the program, always more or less will add some of the printf and other statements for output debugging information, but the printf statement has a very inconvenient place is when we need to publish a program to be a piece of the statement to delete these statements, and once again to debug the time, These statements have to add, which brings us a lot of inconvenience, wasting our time, but also caused the inefficient commissioning. Therefore, many people choose to use the macro definition to output the debug statements.


Compiler built-in macros, the ANSI C standard has several standard scheduled macros (also commonly used):

__line__: Inserts the current source code line number in the source code;
__file__: Inserts the current source filename in the source file;
__date__: Insert the current compilation date in the source file
__time__: Inserts the current compile time in the source file;
__stdc__: The identifier is assigned a value of 1 when the program strictly complies with the ANSI C standard;
__cplusplus: This identifier is defined when you write a C + + program.


Test Source:

#include "stdafx.h" #ifdef _DEBUG      #define DEBUG (format,...)   printf ("File:" __file__ ", Line:%05d:" format "\ n", __line__, # #__VA_ARGS__)  #else      #define DEBUG (format,...)  #endif//!_debug  int _tmain (int argc, _tchar* argv[]) {    DEBUG ("File line Test%d", 1); return 0;}


Test Results:



__FILE__,__LINE__ Output Debugging Information

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.