lkml.org 
[lkml]   [2008]   [May]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectoptimizing out inline functions
In trying to remove some macros, I ran across another kernel style
question. I see two ways that people try to let the compiler optimize
out unused code and would like to know which is preferred. The first
example uses an empty inline function and trusts the compiler will
optimize it out.

#ifdef CONFIG_DEBUG_SOMETHING
static inline void some_debug_function(var1)
{
something = var1;
printk(some debug text);
}
#else
static inline void some_debug_function(var1)
{
/* empty function */
}
#endif


alternatively I have seen places where people put a #define of do while 0, e.g.



#ifdef CONFIG_DEBUG_SOMETHING
static inline void some_debug_function(var1)
{
something = var1;
printk(some debug text);
}
#else
#define some_debug_function(var) do {} while (0)
#endif


Is one or the other style (with or without #define of empty function)
preferred? Does the compiler optimize both #else clauses out
properly? sparse and checkpatch seem to take either

--
Thanks,

Steve


\
 
 \ /
  Last update: 2008-05-28 21:53    [W:0.179 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site