Preprocessor Directives in C Advanced

In the last instructional exercise, I educated you regarding some preprocessor orders which are macros and record incorporation. Two more preprocessor orders are left which I will finish in this instructional exercise.

So today I will educate you concerning the two preprocessor mandates in C language which are

Restrictive aggregation

Different mandates

Restrictive Compilation

The utilization of this preprocessor mandate is like its name. It is regularly used to avoid some arrangement of explanations through the procedure of assemblage. One inquiry which will hit at the forefront of your thoughts.

For what reason would it be advisable for me to compose those explanations which I would prefer not to order?

Well, software engineers regularly compose programs for certain customers. Assume at one phase customer requests the more established rendition of program which you have erased. At that point at those cases, it is utilized generally. So it is frequently used to exclude the working of specific capacities effectively without contacting the code. It is the most secure approach to expel certain code from the program.

It is additionally used to test the working of the program. While composing complex C programs it is frequently that the C program gives wrong outcomes finally minute. So we can utilize restrictive accumulation to amend mistakes by utilizing hit and preliminary technique.

Transportability is one of the fundamental element which is very acclaimed nowadays. With the utilization of restrictive gathering, we can likewise make the program compact.

Presently let’s take one guide to clarify the contingent accumulation.

ifdef MACRO NAME

Articulation 1;

Articulation 2;

Etc…

endif

It implies the announcements 1, 2, etc will possibly work when a large scale is characterized in the program with MACRO NAME. You can likewise utilize #ifndef, it is the only inverse of #ifdef. Here #else can be utilized to show else part of #ifdef or #ifndef. #endif shows the finish of restrictive aggregation preprocessor mandates.

#include<stdio.h>
 
int main()
{
 printf(" Hello! Lets learn conditional compilation");
 
 #ifdef WORK
  printf("This will not work");
 #endif
 
 return 0;
}

Output

Hello! Lets learn conditional compilation

Clarification

As should be obvious, the second printf() doesn’t work. This is on the grounds that we have not characterized any large scale with WORK.

To make the second printf() work, I simply need to include #define WORK before fundamental() work. After that, it will likewise print the message inside the second printf().

Different Directives

The two preprocessor orders that are not generally utilized falls inside the class of different mandates.

undef

#pragma

undef

This preprocessor order is commonly used to undefine certain macros at some stage. It isn’t regularly utilized however we can indistinct any macros by utilizing #undef pursued by the macros name.

pragma

This preprocessor order is commonly utilized in three different ways which are a

a. #pragma startup

b. #pragma exit

c. #pragma caution

In the last instructional exercise I educated you regarding some preprocessor orders which are macros and record incorporation. Two more preprocessor orders are left which I will finish in this instructional exercise.

So today I will educate you concerning the two preprocessor mandates in C language which are

Restrictive aggregation

Different mandates

Restrictive Compilation

The utilization of this preprocessor mandate is like its name. It is regularly used to avoid some arrangement of explanations through the procedure of assemblage. One inquiry which will hit at the forefront of your thoughts.

For what reason would it be advisable for me to compose those explanations which I would prefer not to order?

Well software engineers regularly compose programs for certain customers. Assume at one phase customer requests the more established rendition of program which you have erased. At that point at those cases it is utilized generally. So it is frequently used to exclude the working of specific capacities effectively without contacting the code. It is most secure approach to expel certain code from the program.

It is additionally used to test the working of program. While composing complex C programs it is frequently that the C program gives wrong outcomes finally minute. So we can utilize restrictive accumulation to amend mistakes by utilizing hit and preliminary technique.

Transportability is one of the fundamental element which is very acclaimed nowadays. With the utilization of restrictive gathering we can likewise make the program compact.

Presently lets take one guide to clarify the contingent accumulation.

ifdef MACRONAME

Articulation 1;

Articulation 2;

Etc…

endif

It implies the announcements 1, 2, etc will possibly work when a large scale is characterized in the program with MACRONAME. You can likewise utilize #ifndef, it is only inverse of #ifdef. Here #else can be utilized to show else part of #ifdef or #ifndef. #endif shows the finish of restrictive aggregation preprocessor mandates.

Clarification

As should be obvious, the second printf() doesn’t work. This is on the grounds that we have not characterized any large scale with WORK.

To make the second printf() work, I simply need to include #define WORK before fundamental() work. After that it will likewise print the message inside second printf().

Different Directives

The two preprocessor orders that are not generally utilized falls inside the class of different mandates.

undef

#pragma

undef

This preprocessor order is commonly used to undefine certain macros at some stage. It isn’t regularly utilized however we can indistinct any macros by utilizing #undef pursued by the macros name.

pragma

This preprocessor order is commonly utilized in three different ways which are

a. #pragma startup

b. #pragma exit

c. #pragma caution

pragma startup: This is utilized to call some capacity directly from the beginning up (before executing fundamental() work). We can call any capacity by utilizing this preprocessor order.

Linguistic structure: #pragma startup funcall

In the above code “funcall” capacity will be called from the beginning up of the program.

pragma leave: It is a partner of start up. It is utilized to call some capacity when program closes.

Language structure: #pragma exit funcall

In the above code “funcall” work is called at the exit of the program.

pragma caution: This preprocessor mandate is utilized once in a while. It is commonly used to supress a particular admonition inside a program.

Linguistic structure: #pragma startup funcall

In the above code “funcall” capacity will be called from the beginning up of the program.

pragma leave: It is a partner of a start-up. It is utilized to call some capacity when the program closes.

Language structure: #pragma exit funcall

In the above code “funcall” work is called at the exit of the program.

pragma caution: This preprocessor mandate is utilized once in a while. It is commonly used to suppress a particular admonition inside a program.

Leave a Comment

error: Alert: Content is protected!!