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.



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

 Vote 0

Similar topics related to this section

enum vs macro, macro vs typedef, debug builds, debug macros, compiler macro for C++, FILE, LINE, DATE, TIME, compiler marcos, token pasting, characterizing, array,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan