This means that large (or repeating) sections of code can be abstracted into a preprocessor macro. The C preprocessor is a macro preprocessor (allows you to define macros) that transforms your program before it is compiled.

Though, they are treated in a different way during the compilation procedure.

Because macros don't generate actual function calls, you can sometimes make programs run faster by replacing function calls with macros.

3.2 Function-like Macros.

Macro in C: Macros are defined as single identifiers that are equivalent to expressions, complete statement or groups of statements. All preprocessing directives begin with a # symbol. A C macro is a piece of code that has a specific name called macro name. C library macro - assert() - The C library macro void assert(int expression) allows diagnostic information to be written to the standard error file. Function-like macros can be defined to accept arguments, so that they look and act like function calls. A macro is defined with the preprocessor directive, #define. Macros are treated as a token substitution early in the compilation process. The C preprocessor or cpp is the macro preprocessor for the C, Objective-C and C++ computer programming languages.The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.. Difference between macro and function No Macro Function 1 Macro is Preprocessed Function is Compiled 2 No Type Checking Type Checking is Done 3 Code Length Increases Code Length remains Same 4 Use of macro can lead to side effect No side Effect – 5 Speed of Execution is Faster Speed of Execution is Slower […] The C preprocessor modifies a source code file before handing it over to the compiler.

C++ Macros Example. Multiline macros in C In this article, we will discuss how to write a multi-line macro. Being a pre-processor, the block of code is communicated to the compiler before entering into the actual coding (main function). Macros that do so are called macro functions.To create a macro function, simply define a macro with a parameter that has whatever name you like, such as my_val.For example, one macro defined in the standard libraries is abs, which returns the absolute value of its parameter.Let us define our own version, ABS, below. Whenever the macro name is used, C preprocessor will replace it with the body of the macro. C provides you with two kinds of macros: object-like macros and function-like macros. You can also define macros whose use looks like a function call. Some of the common uses of C preprocessor are:

You're most likely used to using the preprocessor to include files directly into other files, or #define constants, but the preprocessor can also be used to create "inlined" code using macros expanded at compile time and to prevent code from being compiled twice. When you use a function call it will be translated into ASM CALL with all these stack operations to pass parameters and return values. They are defined in an all together different members than functions.

These transformations can be the inclusion of header file, macro expansions etc. What is a C macro.