Some pre-defined macros in the C standard (e.g. __func__, etc.)

Source: Internet
Author: User

Some pre-defined macros in the C standard
Some predefined macros are specified in the C standard and are often used for programming. The following table is a list of some of the predefined macros that are often used.
Macro
Significance
__date__
Date of preprocessing (string literal in the form "MMM DD yyyy")
__file__
string literal representing the current source code file name
__line__
An integer constant representing the line number in the current source code
__time__
Source file compile time, lattice "Hh:mm:ss"
__func__
Name of current function
  
For macros such as __file__,__line__,__func__, it is useful to debug a program, because you can easily know which file the program runs to and which is the function.
The following example prints the predefined macros above.
#include
#include

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 was 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 was line%d.\n", __line__);
}

Printing information:
The file is debug.c.
The date is June 6 2012.
The time is 09:36:28.
This was line 15.
This function is main.
This function is Why_me
The file is debug.c.
This was line 27.

Some pre-defined macros in the C standard (e.g. __func__, etc.)

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.