- UNIT-I (Array)
strlen(),strcpy(),strcat() ,strcmp()
Definition
Macro substitution directives
File inclusion directives
Conditional compilation
Bitwise Operators
Shift operators
Masks
Bitfield
Macro substitution directives
File inclusion directives
Conditional compilation
Bitwise Operators
Shift operators
Masks
Bitfield
Definition
The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process.
Preprocessor programs give preprocessors orders which advise the compiler to preprocess the source code before gathering. These preprocessor orders start with a '#' (hash) image. This ('#') image toward the start of an announcement in a C/C++ program demonstrates that it is a pre-processor order. We can put these preprocessor mandates anyplace in our program
There are 4 main types of preprocessor directives:
- Macros
- File Inclusion
- Conditional Compilation
- Other directives
1. Macros: Macros are a bit of code in a program that is given some name. At whatever point this name is experienced by the compiler replaces the name with the real bit of code. The '#define' mandate is utilized to characterize a full scale. Let us currently comprehend the large scale definition with the assistance of a program:
In the above program, when the compiler executes the word HIGHT it replaces it with 5. The word 'HIGHT' in the large macro definition is known as a macro template and '5' is a macro expansion
2. File Inclusion: This kind of preprocessor order advises the compiler to remember a document for the source code program. There are two sorts of records which can be incorporated by the client in the program:
- Header File or Standard files: these documents contain the meaning of pre-characterized capacities like printf(), scanf() and so forth. These records must be incorporated for working with these capacities. Diverse capacity is proclaimed in various header records. For instance standard, I/O functions are in 'iostream' document though works which perform string activities are in 'string' record Syntax:#include< file_name >
- user defined files: When a program becomes very large, it is good practice to divide it into smaller files and include whenever needed
Syntax #include"filename"
3. Conditional Compilation: Conditional Compilation directives are type of directives which helps to compile a specific portion of the program or to skip compilation of some specific part of the program based on some conditions. This can be done with the help of two preprocessing commands ‘ifdef‘ and ‘endif‘.
Syntax:
Syntax:
#ifdef macro_name
statement1;
statement2;
statement3;
.
.
.
statementN;
#endif
4. Other directives: Apart from the above directives there are two more directives which are not commonly used. These are:
- #undef Directive:
- #pragma Directive: used #pragma startup and #pragma exit
---------------------------------------------------------------------------------------------------------------------------
All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives −
Sr.No. | Directive & Description |
---|---|
1 |
#define
Substitutes a preprocessor macro.
|
2 |
#include
Inserts a particular header from another file.
|
3 |
#undef
Undefines a preprocessor macro.
|
4 |
#ifdef
Returns true if this macro is defined.
|
5 |
#ifndef
Returns true if this macro is not defined.
|
6 |
#if
Tests if a compile time condition is true.
|
7 |
#else
The alternative for #if.
|
8 |
#elif
#else and #if in one statement.
|
9 |
#endif
End preprocessor conditional.
|
10 |
#error
Prints error message on stderr.
|
11 |
#pragma
Issues special commands to the compiler, using a standardized method.
|
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें