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.)