C pre-processor

Facebooktwitterredditpinterestlinkedinmailby feather

The C processor is a macro processor which is used to compile the source code of the program (step by step) . It is not a part of the compiler. All pre-processor commands begin with the hash symbol (#).

The C pre-processor provides various facilities that are:

  • Inclusion of header
  • Macro expansion
  • Conditional compilation
  • Line control


MacroMacro is used to define the constant value and data types.

Syntax: #define

Header file inclusionThe source code of the file “file_name” is included in the main program at the specified place.

Syntax: #include <file_name>

Conditional compilationIt is used to set of commands in source program.

Syntax: #ifdef, #endif, #if, #else, #ifndef

Other directives#undef is used to defined a macro variable and #Pragma is used to call a function before and after main function.

Syntax: #undef, #pragma


C language, there are various stages of the execution process. The given following diagram will help you:


There are following important pre-processor directories in C language.

#defineSubstitutes a pre-processor macro.
#includeIt is used to inserts a particular header from another file.
#undefIt is used to undefine a preprocessor macro.
#ifdefIt is used to return true if this macro is defined.
#ifdefIt is used to return if this macro is defined.
#ifIt is used to check compile time condition.
#elseThe alternative for #if.
#elif#if and #else in one statement.
#endifIt is used to end pre-processor conditional.
#errorIt is used to print an error message on stderr.
#pragmaIssues special command to the compiler, using a standardized method.


Example: 1

Example 2


C Macros

A macro is a name which stands for a fragment of code. Before using macro we must define it with ‘#define’ directive. It is the name of a macro.

There are two types of macros.

  1. Object-like macros
  2. Function-like macros 


  1. Object-Like Macros:

The object-like macro is an identifier that is replaced by value. It is widely used to represent numeric constants.



  1. Function like Macros:

Function like macros is used as a function call. Let us consider an example.

Here MAX is the macro name.

There are some predefined macros :

Predefined MacrosDescription
_DATE_It is defined as the current date with “MMM DD YYY” format.
_TIME_It is defined as current time with “HH:MM:SS” format.
_FILE_It contains the current filename as a string literal.
_STDC_It is defined as 1 when compiler compiles with the ANSI standard.
__STDC_VERSION__It is defined as standard’s version
_GNUC_It is defined if and only if this is  GNU C. etc

Example of Macros



C #define and #include.

C #defined:

It defines constant value. It can be any of the basic data types.


Example: 1






It is used to paste the code of given file into the current file. We can use system-defined and used-defined header files.

There are two types of #include directive.

  1. #include< filename>
  2. #include ”filename”




C #undef:

It is used to check undefined the constant or macro. It is defined by #define.


Example 1:


Example 2:



#ifdef, #else and #endif

The ‘#ifdef’ directive is used to check whether the macro is defined or not. If it is defined then, ‘if’ clause statements are included in the source code.

Otherwise “else” clause statements are included in the source file for compilation and execution.

Example : #ifdef



C #Pragma:

The C #Pragma is used to call a function before and after the main function. It also provides additional information to the compiler.

There are several types of pragmas in GCC compiler.

  • AArch64 Pragmas
  • ARM Pragmas
  • M32C Pragmas
  • MeP Pragmas
  • RS/6000 and PowerPC Praglmas
  • S/390 Pragmas:
  • Darwin Pragmas:
  • Solaris Pragmas: etc.





Facebooktwitterredditpinterestlinkedinmailby feather

Leave a Comment