

The compiler does inlining for performing optimizations. passing arguments variables, return address, return value, stack mantle and its dismantle, etc.) but whether an inline function serves your purpose in a positive or in a negative way depends purely on your code design and is largely debatable. Usually, people say that having an inline function increases performance by saving time of function call overhead (i.e. The compiler interprets the inline keyword as a mere hint or requests to substitute the code of function into its function call. Even there is no guarantee that the function will actually be inlined.

Basically, they are inlined with its function call.

Inline functions are those functions whose definition is small and can be substituted at the place where its function call is made. And, TEST1macro is defined so, the string “ MACRO TEST1 is defined” is printed and since macro TEST3is not defined, so “ MACRO TEST3 is defined” is not printed. Here, we can see that “ commented code 1”, “ commented code 2” are not printed because these lines of code are commented under #if 0 macro. Here, we will understand the above features of macro through the program that is given below. To comment multiples lines of code, the macro is used commonly like below : #if 0 If some part of code needs to be executed for release 1 of the project and some other part of code needs to be executed for release 2, then it can be easily achieved through conditional macros. They are very helpful in large projects having code segregated as per releases of the project. Code snippets are guarded with a condition checking if a certain macro is defined or not. Here are some examples that define macros for swapping numbers, square of numbers, logging function, etc.Ĭonditional macros are very useful to apply conditions.

Function-like macros are very beneficial when the same block of code needs to be executed multiple times. It can be used if any short operation is being done in the program repeatedly. Macros are used for short operations and it avoids function call overhead. Macros are handled by the pre-compiler and are thus guaranteed to be inlined. So, you see that the macro MAX_SIZEwas replaced with its value (10) in preprocessing stage of the compilation process. If you open this file and get to the bottom of this file. The command above will produce all the intermediate files in the GCC compilation process. i ) is produced along with the final executable using the below command. Now let’s compile it with the flag -save-temps so that pre-processing output (a file with an extension. Printf("\n The value of size is \n",size) Now let’s see an example through which we will confirm that macros are replaced by their values at pre-processing time.
