Chinna
Chinna

Reputation: 4002

Why define a macro insted of using directly?(Please see description for what exactly i want)

I am traversing through linux kernel code. I found a macro defined as #define __async_inline __always_inline. I searched for __always_inline,I found the following statement #define __always_inline inline. My question is why they need to do like this? They can directly use inline instead of this macro's?

Upvotes: 5

Views: 144

Answers (2)

JesperE
JesperE

Reputation: 64414

This is a common way to parameterize code, to move a decision of some sort (in this case, the use of inline) to a single place, so that should that decision change (for whatever reason: different compilers, different configuration options, different architectures), there is only one single place to change.

Upvotes: 5

Thomas Ruiz
Thomas Ruiz

Reputation: 3661

The code says this:

#ifdef CONFIG_HAS_DMA
#define __async_inline
#else
#define __async_inline __always_inline
#endif

It is self-explained. __async_inline will be replaced by inline if CONFIG_HAS_DMA is not defined.

Upvotes: 7

Related Questions