So guys welcome back.
In this module we will going to study pre processing directives in C and C++.
So we will understand the working of pre processing 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 pre processing directives and how do they work.
And then we will try to see that how the solution to duplicate inclusion of her defiance could be resolved
using process of directives.
So this will give you a clear insight regarding how pre processing directives work and when should you
use pre processing directives.
So going forward.
Let us strive to understand the problem of duplicate inclusion of header fine.
So most of the times we end up including the same head define into the source file multiple times.
This result in duplicate text substitution.
So result is the compilation error.
So let us strive to understand this with the help of a scenario.
So for example you have two header files that is a dot that and we dotage.
Now you are already familiar with these two header files.
Now suppose application dot c is the source while 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 a dot etch header file so you can
see that in this source file a programmer has hash included both the head of files and rest of the code
in this source file is application specific.
So this is the source file which is budget one and it is this source file which is actually written
by a programmer.
Now let us start to understand that where is the obligate inclusion of header fine
so applying the tax substitution on Version 1 we get the version 2 of application DRC source file so
version 2 of source file is optimized by applying the text substitution of B dot it's hard to find.
So you can see that the statement hash include B dot at is replaced by the content of B.
Each head to define now you can see that we not heard the file already had the statement hash include
a dot edge.
So this leads to to occurrence of hash include a dot at statement in budget two of application DRC file.
Now if you apply the tax substitution again on this wasn't to of application DRC source Fine you get
version 3 Now you can see that the content of a dog edge is repeated twice.
Invasion three of application Nazi swords fight.
It is because the tax substitution has happened twice for a DOT etch header file so you can see that
there is some duplicate U.S. invasion three of application Nazi source file now proceeding to the final
step of tax substitution phase.
Just remove all the has defines from budget three of application Nazi source file and the final version
of source file is actually this application Nazi swords fight so we can see that what 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.
Each had a file and this declaration comes from another occurrence of a dot.
Each had a file.
So this version of application or c file is the final compilation unit which actually visible to the
compiler for compilation.
So when the compiler compiles this final version of application or c file the compiler will through
an error and it will say something like duplicate definition detected and it will give you a compilation
error.
Right.
So you can see that because the programmer cache included both the header finds and b dot s already
contain the statement hash include.
Therefore it resulted in inclusion of a dot s had define twice in the source.
And this leads to this problem.
Now consider a scenario when you have hundreds of header files in your project.
You cannot keep track that which had to file hash include another had to file already and you should.
A wide inclusion of somehow the files explicitly it is very difficult for you to keep track of this
and you would not want to invest your energy in only to decide that rather you should hash include a
particular header file or not.
So this problem of duplicate inclusion of head of file is resolved using pre processing directives.
So now let us strive to understand that what is pre process of directives and how do they work and help
me process of directives can help us to resolve the problem of duplicate inclusion of hydro files.