Preprocessor Directives 367
11.13 THE PREDEFINED MACROS IN ANSI AND TURBO-C
a) ANS I C Predefined M acros The lists of pre-defined macros according to ANSI standard are as
per the Table 11.1. There are five pre-defined macros and are always available to the programmer for
use. They can not be undefined. Every macro name is defined with two underscores as prefix and
suffix. These macros are useful for finding system information such as date, time, and file name and
line number. A program is illustrated for testing these macros.
Table 11.5 Predefined Macros in ANSI -C
Predefined Macros
Function
__
Date
__
Displays system date in string format
__
Time
__
Displays system time in string format
__
Line
__
Displays line number as an integer
__
File
__
Displays current file name in string format
__
Stdc
__
In ANSI 'C' the value returned w ill be non-zero.
11.15 Write a program to use pre-defined macros o f ANSI C.
# include <stdio.h>
# include cconio. h>
# include <stdde£.h>
void main()
{
clrscr();
printf (" n D A T E : % $ " ,_ p A T E _ J ;
printf ( “nT lM E : % s " ,_ T I M E _ ) ;
printf ( “hFTLE N A M E : % s",_JF IL £_J;
printf (" n U N E N O . : % d " ^ _ U N E _ J ;
p rin tfCn_S T D C _ :% x " ,_ S T D C _ > ;
1
OUTPUT
DATE : Dec 05 2001
TIME : 21:07:39
FILE N A M E : PRE_MA~1.C
LINE NO. : 10
_STDC_ : 1
Explanation In the above program five macros are used in theprintf () statements. On its execution
the output of the program is displayed as shown- above. The program displays system date, time,
program file name and total lines in the program. The STDC indicates whether the version of C
compiler follows ANSI 'C' standard. Here, the result is one. Hence, the compiler follows ANSI C
standards-. The programmer should set ANSI keyword on option by selecting option menu of the
editor - compiler-source- ANSI keywords only on.
b) Turbo C Predefined Macros The pre-defined macros in Turbo c are listed in the table. The
programmer can use the macro
__
TURBOC
__
to find the version of Turbo. By setting option of code