{"id":14037,"date":"2023-02-23T14:10:48","date_gmt":"2023-02-23T08:40:48","guid":{"rendered":"https:\/\/fastbitlab.com\/?p=14037"},"modified":"2023-09-16T12:53:17","modified_gmt":"2023-09-16T07:23:17","slug":"microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 182| Conditional compilation directives"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 35px; border-width: 0px; line-height: 50px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #000080;\">Conditional compilation directives<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: 0px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-size: 25px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #d44815;\"><b>Conditional compilation in \u2018C\u2019<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">There are various conditional compilation directives available in the &#8216;C&#8217; programming language.&nbsp; These are some of the conditional compilation directives, as shown below.<\/span><\/p>\n<p class=\"\" style=\"padding-left: 40px; font-size: 17px; line-height: 30px; font-family: 'Open Sans'; font-weight: 400; box-shadow: #cecece 0px 0px 0px 0px; background-color: rgba(66, 3, 149, 0.34);\" data-font-family=\"Open Sans\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ffffff;\"><strong>#if<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>#ifdef<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>#endif<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>#else<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>#undef<\/strong><\/span><br \/>\n<span style=\"color: #ffffff;\"><strong>#ifndef<\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">These directives help you to include or exclude individual code blocks based on various conditions set in the program.&nbsp;<\/span><\/p>\n<figure id=\"attachment_14043\" aria-describedby=\"caption-attachment-14043\" style=\"width: 642px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-14043\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-1-11.png\" alt=\"Conditional compilation directives in C\" width=\"642\" height=\"235\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11.png 1757w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11-300x110.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11-1024x375.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11-768x281.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11-600x220.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11-1536x562.png 1536w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><figcaption id=\"caption-attachment-14043\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Conditional compilation in \u2018C\u2019<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let&#8217;s explore how to use these conditional compilation directives.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 25px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong><span style=\"text-decoration: underline;\">#if and #endif directive<\/span><\/strong><\/span><\/p>\n<figure id=\"attachment_14044\" aria-describedby=\"caption-attachment-14044\" style=\"width: 598px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-14044\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-2-9.png\" alt=\"Figure 2. #if and #endif directive - Conditional compilation directives in C\" width=\"598\" height=\"308\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-9.png 1833w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-9-300x155.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-9-1024x528.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-9-768x396.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-9-600x309.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-2-9-1536x792.png 1536w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/><figcaption id=\"caption-attachment-14044\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. #if and #endif directive<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #ff0000;\"><b>Syntax:<\/b><\/span><b> <\/b><\/p>\n<pre class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #003366;\">#if&lt;constant expression&gt;<\/span>\r\n\r\n<span style=\"color: #003366;\">#endif<\/span><\/pre>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">You have to write <\/span><b>#if<\/b><span style=\"font-weight: 400;\"> followed by a constant expression. So, this must be a number or an integer. Like 0 or non-zero value.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #ff0000;\"><b>Example<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here, #if 0, then you can write your code block, and the scope of the <\/span><b>if<\/b><span style=\"font-weight: 400;\"> is marked or decided by the following <\/span><span style=\"color: #003366;\"><b>endif<\/b><\/span><span style=\"font-weight: 400;\">. That&#8217;s why the endif always should follow an if.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This directive checks whether the constant expression is a zero or non-zero value.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the constant is 0, then the code block will not be included for the code compilation.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the constant is non zero, the code block will be included for the code compilation.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #003366;\"><b>endif<\/b><\/span><span style=\"font-weight: 400;\"><span style=\"color: #000000;\"> directive marks the end of scope of #if, #ifdef, #ifndef, #else, #elif directives.<\/span>&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Please don&#8217;t confuse this <span style=\"color: #003366;\">&#8216;<\/span><\/span><b><span style=\"color: #003366;\">if<\/span>&#8216;<\/b><span style=\"font-weight: 400;\"> with your decision-making if statement, both are entirely different. This is a conditional compilation directive, that \u2018if\u2019 is a &#8216;C&#8217; statement. So, that \u2018if\u2019 what we use in decision-making is an if statement. So, that is checked during the runtime of the program. But this #if and #endif is checked during the pre-processor stage of the compilation, whether to include a code block or not in the final executable of the program.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this case, this code block will not be part of the final executable of the program. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #ff0000;\">How to use&nbsp; #if and #endif in a program?<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">#if<\/span> 0\r\n<span style=\"color: #ff99cc;\">   float<\/span> radius = 0;\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"This is circle area calculation program\\n\");\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"Enter the radius :\");\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">   scanf<\/span>(\"%f\", &amp;radius);\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"Area of circle = %f\\n\",(3.1415 * radius * radius));\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n<span style=\"color: #ff99cc;\">#endif<\/span>\r\n\r\n<span style=\"color: #ff99cc;\">   float<\/span> base, height;\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"This is Triangle area calculation program\\n\");\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"Enter base and height: \");\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">   scanf<\/span>(\"%f%f\",&amp;base, &amp;height);\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"Area of triangle = %f\\n\", (0.5 * base * height));\r\n<span style=\"color: #ff99cc;\">   return<\/span> 0;<\/pre>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now here in this program, there are 2 code blocks. The first code block actually computes the area of a circle and the second code block computes the area of a triangle.<\/span><\/p>\n<figure id=\"attachment_14045\" aria-describedby=\"caption-attachment-14045\" style=\"width: 692px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-14045\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-3-7.png\" alt=\"Conditional compilation directives in C\" width=\"692\" height=\"352\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-7.png 1487w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-7-300x153.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-7-1024x521.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-7-768x391.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-3-7-600x305.png 600w\" sizes=\"(max-width: 692px) 100vw, 692px\" \/><figcaption id=\"caption-attachment-14045\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Example<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In programs, you use comments to exclude the sentences. But comments are generally used to give some description or to provide some information. So, using that to remove a code block is not good.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Instead of that you can use <\/span>pre-processor directive<b> <span style=\"color: #000080;\">#if<\/span><\/b><span style=\"font-weight: 400;\">.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Please note that you should remember 2 points:<\/span><\/p>\n<ol class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"font-weight: 400; color: #000000;\"> It must be a constant expression here.<\/span><\/li>\n<li><span style=\"color: #000000;\"><span style=\"font-weight: 400;\"> And this <\/span><span style=\"color: #000080;\"><b>#if<\/b><\/span><span style=\"font-weight: 400;\"> must be terminated by its associated <\/span><span style=\"color: #000080;\"><b>#endif<\/b><\/span><span style=\"font-weight: 400;\">, otherwise you will face problems.&nbsp;<\/span><\/span><\/li>\n<\/ol>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Look at Figure 3, I can use <\/span><span style=\"color: #000080;\"><b>#if<\/b> <b>0<\/b><\/span><span style=\"font-weight: 400;\">. A <\/span><span style=\"color: #000080;\"><b>#if<\/b><\/span><span style=\"font-weight: 400;\"> must be terminated by its associated <\/span><span style=\"color: #000080;\"><b>#endif<\/b><\/span><span style=\"font-weight: 400;\">. #endif actually decides the scope of this. So, now this code block is excluded from the build itself.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the output, you can see that it directly goes to the second code block. It is not executing the first code block(Figure 3).&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>#if \u2026#else \u2026\u2026#endif<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The #if, #else, and #endif are conditional compilation directives that are used in programming languages like C, C++, and C# to include or exclude parts of the code based on certain conditions.<\/span><\/p>\n<figure id=\"attachment_14046\" aria-describedby=\"caption-attachment-14046\" style=\"width: 611px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14046\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-4-7.png\" alt=\"Figure 4. #if \u2026#else \u2026#endif - Conditional compilation directives in C\" width=\"611\" height=\"314\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-7.png 1739w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-7-300x154.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-7-1024x526.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-7-768x394.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-7-600x308.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-4-7-1536x789.png 1536w\" sizes=\"(max-width: 611px) 100vw, 611px\" \/><figcaption id=\"caption-attachment-14046\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. #if \u2026#else \u2026#endif<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #ff6600;\"><b>Syntax:<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">You can also use <\/span><span style=\"color: #000080;\"><b>#else<\/b><\/span><span style=\"font-weight: 400;\"> in between <\/span><span style=\"color: #000080;\"><b>#if<\/b><\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"color: #000080;\"><b>#endif<\/b><\/span><span style=\"font-weight: 400;\">, as shown in Figure 4.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The #if directive tests whether a particular condition is true or false. And if it is true, the code between the #if and the corresponding #else or #endif directive is included in the compiled output. If the condition is false, the code between the #if and #else directives is skipped, and the code between #else and #endif directives (if present) is included instead.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The #else directive is optional and is used to specify an alternate code block that should be included in the compiled output when the condition tested by the preceding #if directive is false.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The #endif directive is used to mark the end of a conditional block and is required after every #if or #else directive.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #ff6600;\"><b>Example<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, a&nbsp; #if constant expression is 1. So, code block-1 will be included for the build, and code block-2 will not be considered for the build.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Suppose, #if constant expression is 0, then code block-2 will be considered for the build.&nbsp; <\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let\u2019s see how you use this in a program, as shown in below.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the program, I use #if constant expression 1, after the code block-1 I will use #else, and then after the code block-2 I use #endif.&nbsp;&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this case, the #if block will be included in the compiled output, and it prints an area calculation program.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So I use if 0, in that case, the second code block will be the output.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">That&#8217;s why use&nbsp; #else when you want to execute either one of the code blocks.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">#if<\/span> 1\r\n<span style=\"color: #ff99cc;\">   float<\/span> radius = 0;\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"This is circle area calculation program\\n\");\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"Enter the radius :\");\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">   scanf<\/span>(\"%f\", &amp;radius);\r\n<span style=\"color: #ff00ff;\">   printf<\/span>(\"Area of circle = %f\\n\",(3.1415 * radius * radius));\r\n<span style=\"color: #ff00ff;\">   fflush<\/span>(stdout);\r\n\r\n\r\n<span style=\"color: #ff99cc;\">#else<\/span>\r\n<span style=\"color: #ff99cc;\">  float<\/span> base, height;\r\n<span style=\"color: #ff00ff;\">  printf<\/span>(\"This is Triangle area calculation program\\n\");\r\n<span style=\"color: #ff00ff;\">  fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">  printf<\/span>(\"Enter base and height: \");\r\n<span style=\"color: #ff00ff;\">  fflush<\/span>(stdout);\r\n<span style=\"color: #ff00ff;\">  scanf<\/span>(\"%f%f\",&amp;base, &amp;height);\r\n<span style=\"color: #ff00ff;\">  printf<\/span>(\"Area of triangle = %f\\n\", (0.5 * base * height));\r\n<span style=\"color: #ff99cc;\">#endif<\/span>\r\n\r\n<span style=\"color: #ff99cc;\">return<\/span> 0;<\/pre>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>#ifdef<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here as its name indicates so the evaluation of this pre-processor directive depends upon the definition of a macro. That&#8217;s why it is called <\/span><b>#ifdef<\/b><span style=\"font-weight: 400;\"> (that is if defined).<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">That&#8217;s the reason we use an identifier for the evaluation, so not a constant expression.<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<figure id=\"attachment_14048\" aria-describedby=\"caption-attachment-14048\" style=\"width: 606px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14048 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-6-5.png\" alt=\"Figure 6. #ifdef\" width=\"606\" height=\"204\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-5.png 1712w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-5-300x101.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-5-1024x345.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-5-768x258.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-5-600x202.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-6-5-1536x517.png 1536w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><figcaption id=\"caption-attachment-14048\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. #ifdef<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<blockquote class=\"\">\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>#ifdef directive checks whether the identifier is defined in the program or not. If the identifier is defined, the code block will be included for compilation.&nbsp;<\/b><\/span><\/p>\n<\/blockquote>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #ff6600;\"><span style=\"text-decoration: underline;\"><b>Syntax:<\/b><\/span><b> <\/b><\/span><span style=\"font-weight: 400; color: #000000;\">#ifdef, there is a space and you should use an identifier. And as usual, you have to use endif to terminate the scope.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #ff6600;\"><b>Example<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the NEW_FEATURE macro is defined in the program, then only include the code block, otherwise exclude the code block. That&#8217;s the meaning of those statements.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>#ifndef<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The meaning of this code block is, if a new feature is not defined then it executes the code block.&nbsp; <\/span><\/p>\n<figure id=\"attachment_14049\" aria-describedby=\"caption-attachment-14049\" style=\"width: 629px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14049 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-7-4.png\" alt=\"Figure 7. #ifndef\" width=\"629\" height=\"309\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-4.png 1763w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-4-300x148.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-4-1024x504.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-4-768x378.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-4-600x295.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-7-4-1536x755.png 1536w\" sizes=\"(max-width: 629px) 100vw, 629px\" \/><figcaption id=\"caption-attachment-14049\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. #ifndef<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 25px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>#ifdef and #else<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now you can also use #else along with&nbsp; #ifdef.<\/span><\/p>\n<figure id=\"attachment_14050\" aria-describedby=\"caption-attachment-14050\" style=\"width: 465px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14050 \" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/02\/Figure-8-3.png\" alt=\"Figure 8. #ifdef and #else\" width=\"465\" height=\"210\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-3.png 1894w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-3-300x135.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-3-1024x462.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-3-768x346.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-3-600x271.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-8-3-1536x693.png 1536w\" sizes=\"(max-width: 465px) 100vw, 465px\" \/><figcaption id=\"caption-attachment-14050\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. #ifdef and #else<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the NEW_FEATURE macro is really defined, then the code block of the new feature will be included. If the NEW_FEATURE macro is not defined, then the code block for the old feature will be included.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the following article, let&#8217;s learn about the<a href=\"https:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-183-defined-operator\/\"> #if and &#8216;defined&#8217;<\/a> operators.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px;\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 18px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #993366;\"><strong>Get the Microcontroller Embedded C Programming Full Course<\/strong> <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/www.udemy.com\/course\/microcontroller-embedded-c-programming\/\">Here<\/a>.<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 23px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; border-width: 0px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span><span style=\"color: #0000ff;\">&nbsp;<\/span><\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Conditional compilation directives &nbsp; Conditional compilation in \u2018C\u2019 There are various conditional compilation directives available in the &#8216;C&#8217; programming language.&nbsp; These are some of the conditional compilation directives, as shown below. #if #ifdef #endif #else #undef #ifndef These directives help you to include or exclude individual code blocks based on various conditions set in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":14043,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"enable","ocean_disable_heading":"default","ocean_post_title":"Conditional compilation directives in C","ocean_post_subheading":"","ocean_post_title_style":"solid-color","ocean_post_title_background_color":"#01569b","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-14037","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Conditional compilation directives in C- #if, #ifdef, #endif, #else, #ifndef<\/title>\n<meta name=\"description\" content=\"Conditional compilation directives in C. #if, #ifdef, #endif, #else, #undef, #ifndef these directives help you to include or exclude\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Conditional compilation directives in C- #if, #ifdef, #endif, #else, #ifndef\" \/>\n<meta property=\"og:description\" content=\"Conditional compilation directives in C. #if, #ifdef, #endif, #else, #undef, #ifndef these directives help you to include or exclude\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-23T08:40:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-16T07:23:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1757\" \/>\n\t<meta property=\"og:image:height\" content=\"643\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 182| Conditional compilation directives\",\"datePublished\":\"2023-02-23T08:40:48+00:00\",\"dateModified\":\"2023-09-16T07:23:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/\"},\"wordCount\":1114,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-1-11.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/\",\"name\":\"Conditional compilation directives in C- #if, #ifdef, #endif, #else, #ifndef\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-1-11.png\",\"datePublished\":\"2023-02-23T08:40:48+00:00\",\"dateModified\":\"2023-09-16T07:23:17+00:00\",\"description\":\"Conditional compilation directives in C. #if, #ifdef, #endif, #else, #undef, #ifndef these directives help you to include or exclude\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-1-11.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/Figure-1-11.png\",\"width\":1757,\"height\":643,\"caption\":\"Figure 1. Conditional compilation in \u2018C\u2019\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 182| Conditional compilation directives\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Conditional compilation directives in C- #if, #ifdef, #endif, #else, #ifndef","description":"Conditional compilation directives in C. #if, #ifdef, #endif, #else, #undef, #ifndef these directives help you to include or exclude","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/","og_locale":"en_US","og_type":"article","og_title":"Conditional compilation directives in C- #if, #ifdef, #endif, #else, #ifndef","og_description":"Conditional compilation directives in C. #if, #ifdef, #endif, #else, #undef, #ifndef these directives help you to include or exclude","og_url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2023-02-23T08:40:48+00:00","article_modified_time":"2023-09-16T07:23:17+00:00","og_image":[{"width":1757,"height":643,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 182| Conditional compilation directives","datePublished":"2023-02-23T08:40:48+00:00","dateModified":"2023-09-16T07:23:17+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/"},"wordCount":1114,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/","url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/","name":"Conditional compilation directives in C- #if, #ifdef, #endif, #else, #ifndef","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11.png","datePublished":"2023-02-23T08:40:48+00:00","dateModified":"2023-09-16T07:23:17+00:00","description":"Conditional compilation directives in C. #if, #ifdef, #endif, #else, #undef, #ifndef these directives help you to include or exclude","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/02\/Figure-1-11.png","width":1757,"height":643,"caption":"Figure 1. Conditional compilation in \u2018C\u2019"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-182-conditional-compilation-directives\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 182| Conditional compilation directives"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=14037"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14037\/revisions"}],"predecessor-version":[{"id":15975,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/14037\/revisions\/15975"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/14043"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=14037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=14037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=14037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}