So, guys, welcome back.
In this module, we will going to study preprocessing directives in C and C++ so we will understand
the working of preprocessing directives by following the following part.
First of all, we will discuss the problem of duplicate inclusion of header files.
Then we will learn that what are preprocessing directives and how do they work?
And then we will try to see that how the solution to duplicate inclusion of how the files could be resolved
using preprocessor directives.
So this will give you a clear insight regarding how preprocessing directives work.
And when should you use preprocessing directives?
So going forward, let us try to understand the problem of duplicate inclusion of header file.
So most of the times we end up including the same header file into the source file multiple times.
This result in duplicate text substitution.
So the result is the compilation error.
So let us try to understand this with the help of a scenario.
So, for example, you have two header files, that is eight audits.
And we dautrich.
Now, you are already familiar with these two header fines.
Now, suppose Application Dawsey is the source file, which is written by a programmer.
And this programmer wishes to use the facilities, which is provided by these two header files.
That is, a programmer wishes to use minimum macro or multiplier function, or he wishes to use max
macro or some function which is provided by aid, not each High-Profile.
So you can see that in the source file, a programmer has hash included both the header finds and rest
of the code, and this source file is application specific.
So this is the source file, which is version one.
And it is this source file which is actually written by a programmer.
Now, let us try to understand that.
Where is that duplicate inclusion of header fight?
So applying the tax substitution on version one, we got the version two of application dorse source
file.
So version two of source file is obtained by applying the tax substitution of Bidart.
It's hard to find.
So you can see that that statement has included that at is replaced by the content of Benot.
Each had a file.
Now you can see that we not ahead of file already had the statement has included dot edge.
So this leads to two occurrence of hash included not at statement in version two of application not
see file.
Now if you apply the tax substitution again on this wasn't true of application Nazi source file, you
got voluntary.
Now you can see that the content of airport ad is repeated Goliath's inventory of application Nazi source
file.
It is because the tax substitution has happened twice for a dot.
It's had a file.
So you can see that there is some duplicate SC inventory of application dot source file.
Now proceeding to the final step of tax substitution face.
Just remove all the has defiance from version three of application dorse source file.
And the final version of source file is actually this application dorse source file.
So you can see that White remains in the final version of the source file contains the duplicate declaration
of some functions.
So this declaration comes from one occurrence of a dot eterna file.
And this declaration comes from another occurrence of aid, not ahead of file.
So this version of application Doxy File is the final compilation unit which actually visible to the
compiler for compilation.
So when the compiler compiles this final version of application Nazi file, the compiler will throw
an error and it will say something like duplicate definition detected, and it will give you compilation
error.
Right.
So you can see that because the programmer has included both the header files and Bidart that's already
contained, the statement has included, therefore it resulted in inclusion of a patch, had a file
twice in the source file.
And this leads to this problem.
Now, consider a scenario when you have hundreds of halophiles in your project, you cannot keep track
that which had to file has to include another had to find already.
And you should avoid inclusion of some of the files explicitly.
It is very difficult for you to keep track of this.
And you would not want to invest your energy and only to decide that whether you should include a particular
header file or not.
So this problem of duplicate inclusion of how to file is resolved using preprocessing directives.
So now let us try to understand that what is preprocessor directives and how do they work and how preprocessor
directives can help us to resolve the problem of duplicate inclusion of header files.