Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 985
Chinna Avatar asked Dec 19 '13 09:12

Chinna


2 Answers

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.

like image 53
Thomas Ruiz Avatar answered Nov 20 '22 19:11

Thomas Ruiz


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.

like image 5
JesperE Avatar answered Nov 20 '22 19:11

JesperE