Does C Preprocessor Understand Single Backslash for Continuing Line
With the requirement to include file inclusion procedures present in PL/I and BPCL, the preprocessors were introduced in C at the time of 1973 with the request of Alan Snyder. The initial version of the preprocessor provided only file inclusion procedures and string replacement through #include and #define. Whereas the later versions of (John Reiser and Mike Lesk) offered macros together with arguments and conditional compilations. That's how the development of the preprocessor took place and now this article helps us in knowing the preprocessor definition, syntax, types, commands, and its advantages.
What is Preprocessor?
In the C programming, during code compilation, a person expects the compiler performs code compilation as per how the code is written, but this is not the actual scenario. Before code compilation, the file where the code is written passes through a stage called translation which is termed a translation unit. So, the C preprocessor definition is termed as a macro processor which the C compiler automatically uses it for the transformation of the program prior to the compilation phase. This preprocessor is termed as a macro because one can define macros (short abbreviations for lengthy constructs).
The preprocessor scans every code file and looks for preprocessor directives (directives) and they have their own syntaxes. These directives are the instructions that start with a preprocessor symbol # and ends with a newline. The directives allow the preprocessor to execute specific text manipulation operations. The output from this stage passes through many translation stages and then moves to the compilation phase.
The below picture shows the chain of tasks in a preprocessor.
Types
These preprocessor commands are identified with a preprocessor symbol '#' followed by the identifier and name of the directive. A few of the types of preprocessor in C are:
- Header files inclusion
- Macros expansion
- Conditional compilation
- Line controlling
A few of the types in preprocessor directives are explained as follows:
Macros
Every macro is provided with some name and these macros are some portion of code in the program. At the time, when the compiler observes the macro name, it substitutes the name with actual code. #define is the preprocessor directive used in defining a macro.
The preprocessor syntax for define is
#define taken value
#define AREA (a, b) (a * b) – function like macros
#define PI 3.14
Example –
#include <stdio.h>
#define LIMIT 10
int main()
{
for (int p = 0; p < LIMIT; p++) {
Printf("%d \n", p);
}
return 0;
}
As per the above example, 'LIMIT' is termed as a macro template, and '10' is termed as a macro expansion.
File Inclusion
The file inclusion directive allows the compiler to include a source code file in the program and a person can include two kinds of files in the program which are:
Standard/Header files – The header files consist of pre-defined functions such as scanf(), print(), and others. In order to use the operations in those files, one must include the corresponding header files. There exist various types of header files for various operations where string file contains string operations and iostream contains input and output functions.
The syntax is
#include <file name>
User-Defined files – When there is a lengthy program, the user can divide it into smaller files and include corresponding functions. The syntax for user defines files is #define "filename".
Conditional Compilation
These directives help in deciding whether some portion of the code can be compiled or not depending on a few rules/conditions. This decision can be done using two preprocessor directives which are endif and ifdef. The syntax is:
#ifdef MACRO_NAME
Statement a;
Statement b;
.
.
Statement N;
Post a Comment for "Does C Preprocessor Understand Single Backslash for Continuing Line"