So guys now going forward.
Now let us discuss the solution to the problem of duplicate inclusion of her profile which we had discussed.
So now doing a little recap here.
We had the same set of her profile.
That is a shortage and b dotage.
And following is the definition of d to her defines so these are exactly the same header files which
we had discussed last time and the developer wrote application or C source file and let us call this
file as was in one of application Nazi source file.
So wasn't one of application Dorsey is actually the court which was written by the programmer or developer.
Now if you remember that when you apply the tax substitution on the source file we ended up in compilation
error.
Why.
Because the inclusion of high profile B dot edge leads to the duplicate inclusion of her profile a dot
edge because of it in the final code which the compiler compiles.
There was duplicate declaration of this some function
so the last time our code did not compile.
Now of course the developer cannot prevent from hash including B dot s because maybe the developer wants
to make use of minimum function on Multiply function which is provided by had a file B dot edge.
Therefore the developer has no choice other than to include both the header finds no let us see that
help reprocessing detectives can prevent the problem of duplicate inclusion of high profile.
So of course there is no need to make any changes in application Nazi file as a solution to this problem.
The changes needs to be made in header fines so the content of the header file needs to be sandwiched
between hash if not defined and the corresponding hash and if pre processing directive.
Similarly in v dot s header file just send which the entire content of DOT s had a file in between hash
if not defined pre processing detective and the corresponding hash and if pre processing directive.
So this is a technique which we use in order to avoid the problem of duplicate inclusion of head of
file in C and C++.
So now let us see that what is the impact of including these pre processing directives.
In the beginning and end of the header finds.
So now giving the revised definition of how to file a dot at and b dot edge.
Let us now apply the tax substitution in the similar way that we applied before
so you can see that in the first boss the peoples inductive hash include a dot S is replaced by the
content of a dot 800 file and the pre processing directive has to include re dot Ed is replaced by the
content of B dot it's head of line and of course this has defined is replaced by its definition in the
source while so what we opt in after the tax the student pass one is the vision two of the source fine.
Now this version 2 of the source file is still contains one has include a statement.
So again apply the tax substitution pass to and we will get the version 3 of application Dorsey's source
file.
So you can see that invasion three of the source file this statement is replaced by the content of a
by the content of a dot etc. fine.
Now invasion three of the source while there is more hash include pre processing directive anywhere.
So remember this is the budget three off application or C source file and now going forward.
This is the version 3 of application or source file which we have continued from the previous slide.
Now as a final step of tax substitution phase we will now process all the conditional pre processing
directives from top to bottom.
So as a result of processing conditional pre processing detectives there will be some part of the code
which will be completely omitted out and will not be a part of final compiling all code.
So now let us process all the pre processing directives from top to bottom.
So the first line says that if not defined symbol eight.
Now of course there is more symbol a.
The compiler has seen yet as it is a first line of the source file.
Therefore this condition will be true and the compiler will define the symbol a.
So this line will be a part of the code similarly.
This line will be a part of the code.
And this line also in the same way the compiler has not yet seen the symbol B.
Therefore this condition will be true.
Now the compiler has defined the symbol B.
Now this condition will be false.
Why it is false because the compiler has already defined the symbol a.
Therefore this condition will be false.
This will not be a part of code
so going forward this will be a part of the code.
This will be a part of the code and this will be a part of the code so the remaining lines in this file
will obviously be a part of the code.
Now after pre processing all the conditional pre processing directives from top to bottom.
Now remove all the statements which starts with hash.
So the final code that you get is the Virgin form of application Nazi file.
And you can see that in this final version of application Nazi file there is exactly one declaration
of some function and therefore discord is compiling all code so file air dot edge has been prevented
from including in application multiple times.
Why.
Because of hash if not defined pre processing directives so now make a thumb rule from now for the rest
of your life that whenever you write a high profile make it as a principle of your life that you always
sandwich the entire content of the header file with hash if not defined pre processing directive.
In fact in the production code if you write a hard to file without using this technique you will be
definitely reprimanded by a manager audio or trivial work.
So now you can see that it really doesn't matter how many times you hash include the same hair to fight
directly or indirectly in the same source file.
This technique will prevent the inclusion of same high profile multiple times in the source fine and
the accord will always combine.
So let us summarize this solution so you can see that this is the final version of source file.
Then the header file was not sent w using hash if not defined people's inductive.
And this final version of source file there were duplicate degradation of the function some and because
of this the compilation of application dark c file failed but in the second case we have application
dark c file in which there is exactly one declaration of this function some it is because in the header
file we have used the technique of pre processing directives to prevent the duplicate inclusion of her
defiance and therefore this code combines so this shows the comparison between the final version of
application or c file Van pre processing directive technique was not used and when pre processing directive
technique was used to prevent the duplicate inclusion of her profile.
So make a principle of your life that you will write a high profile starting with hash if not define
an ending with hash and if.