Compilers have inherent macros defined for source file path, current line number, date and time etc. These macros have been listed below:

__FILE__ : File Name
__LINE__ : Line Numder
__DATE__ : Compilation Date
__TIME__ : Compilation Time

Example:
#include <stdio.h>

int main (int argc, char * argv[])
{

  printf ("File Name : %s, Line Numder %d, Compilation Date %s, Compilation Time %s\n",
          __FILE__,
          __LINE__,
          __DATE__,
          __TIME__);
  return 0;
}

Output:
#gcc cp_macros.c 
# date
Thu Dec 27 11:26:44 IST 2012
# ./a.out
File Name : cp_macros.c, Line Numder 8, Compilation Date Dec 27 2012, Compilation Time 11:22:22
# date
Thu Dec 27 11:27:14 IST 2012
# ./a.out
File Name : cp_macros.c, Line Numder 8, Compilation Date Dec 27 2012, Compilation Time 11:22:22
# 
Please note: This date and time is the date and time of compilation not system time.

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.

#