C language debugging c standard macro debugging method

Source: Internet
Author: User

Some predefined macros are specified in the c standard and are often used in programming. The following table lists some predefined macros that are frequently used.


_ DATE __
Date of preprocessing (string text in the form of "Mmm dd yyyy)


_ FILE __
String text representing the current source code file name


_ LINE __
An integer constant representing the row number in the current source code.


_ TIME __
Source File Compilation Time, in the format of "hh: mm: ss"


_ Func __
Current function name

 


It is useful for macros such as _ FILE __,__ LINE __,__ func _ in program debugging, because you can easily know the row of the file to which the program runs and the function.


The following example prints the predefined macros.

 


# Include <stdio. h>
# Include <stdlib. h>
Void why_me ();
Int main ()
{
Printf ("The file is % s. \ n", _ FILE __);
Printf ("The date is % s. \ n", _ DATE __);
Printf ("The time is % s. \ n", _ TIME __);
Printf ("This is line % d. \ n", _ LINE __);
Printf ("This function is % s. \ n", _ func __);
Why_me ();
Return 0;
}


Void why_me ()
{
Printf ("This function is % s \ n", _ func __);
Printf ("The file is % s. \ n", _ FILE __);
Printf ("This is line % d. \ n", _ LINE __);
}

 


/* Note that I tested the above Code on the C/C ++ compiler and found that _ func _ is not defined under VC6.0 */


Author: lifeiaidajia

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.