optimizing out inline functions

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Steve French
Date: Wednesday, May 28, 2008 - 12:51 pm

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
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
optimizing out inline functions, Steve French, (Wed May 28, 12:51 pm)
Re: optimizing out inline functions, Pekka Enberg, (Wed May 28, 12:54 pm)
Re: optimizing out inline functions, Sam Ravnborg, (Wed May 28, 1:00 pm)
Re: optimizing out inline functions, Andrew Morton, (Thu May 29, 1:40 am)
Re: optimizing out inline functions, Steve French, (Thu May 29, 9:39 am)
Re: optimizing out inline functions, Sam Ravnborg, (Thu May 29, 10:20 am)
Re: optimizing out inline functions, Vegard Nossum, (Mon Jun 2, 2:38 am)