UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

14.11.4.  Defining macros with the #define directive

The #define directive has an extra functionality that can be used to define what is known as macros. The replacement done by the preprocessor of a symbol by its equivalent can include parameters. In the following example, a macro is defined to replace the symbol TOO_BIG(v) with the comparison of v with the value 1000.

#define TOO_BIG(v) (v >= 1000)

The TOO_BIG(v) macro can be used in the code with a variable name instead of v which will be used to replace the symbol by its equivalent as it is shown in the following example:

int i;
if (TOO_BIG(i))  /* Source Code */
{ 
  ...
}

if ((i >= 1000))  /* Code received by the translator */
{ 
  ...
}