The preprocessor is a program that is invoked by the compiler. Due to this invokment compiler process code before copulation commands for the program is known as directives. Our lines of the source file beginning with the character hash. This hash distinguishes them from lines of source program.
If you are interested to do Machine learning (Embedded system) course through online, with certification and proper placement log on to Udacity (use this link for sign up, thus you get 1000 rs discount in your first enrolment).
- 1 Look this practical problem which need the requirment of Preprossesor :
- 2 How can we use Preprossesor to solve the problem ?
- 3 Example program : The Key point
- 4 Click here for Previous chapters
Look this practical problem which need the requirment of Preprossesor :
Preprocessors are used to simplify the program source code writing and it can save a lot of development time. Imagine that you are developing a PC based application for rented car booking system. You have choosen blue
color for alt text to be answered on the screen. This color is approved by the client too. But at the end of the project he comes up with a request to change in this color from blue to black. You have used this color value at minimum 500 times in your source code. now to fulfill clients request you have to carefully change out 500 places from blue to black. If you use preprocessor, you can save your work of replacing the text from blue to black only at one global place.
How can we use Preprossesor to solve the problem ?
let’s see how preprocessor can do this for us. Preprocessors are various types here I will discuss the commonly used types. The problem, I discussed just now can be solved using hash define preprocessor. You can write the hash
defined source line in the initial part of your source code file and use the token color in all the places, where you need to specify the text color in all future changes. You have to simply modify the hash defined section from hash define color blue – define color black. Rewriting of basic commands and function by using ‘hash include’.
Preprocessor ‘hash include’ is used to include another file into your program. Thus you can use functions and variables, defined in the other file into your program. The commonly used preprocessor is conditional compiling, hash if and hash else. This helps us to compile the file with some conditions.
Example program : The Key point
Look into the above programming code. Here if section is compiled, provided the debug token is declared
earlier in the code we have written a new file named my def dot H (you can see it in the below image)
This file holds the Declaration of various tokens and variables, which are commonly required for a particular program. We can include this file into our main source file fusing a hash include’ preprocessor as shown on the image.
we will upload next chapter soon. If you didnt saw previous chapters please click on the links below.