In C programming, macros are short pieces of code. You can use these macros as a shorthand for C code, with or without parameters. This enables you to create short, function-like code snippets designed to fulfill a specific task. These can then be used in the code proper and can help to increase readability, while reducing the possibility of mistyping complex code segments.
One common implementation problem revolves around defining a function that’s capable of returning the smaller of two values. Let’s call this function min. There are several ways in which you can implement the min function:
Inline, as an if expression
As a function returning a value
As a macro
In the first case, you might write a condition test as follows: