public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* optimizing out inline functions
@ 2008-05-28 19:51 Steve French
  2008-05-28 19:54 ` Pekka Enberg
  2008-05-28 20:00 ` Sam Ravnborg
  0 siblings, 2 replies; 12+ messages in thread
From: Steve French @ 2008-05-28 19:51 UTC (permalink / raw)
  To: lkml

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-06-02  9:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <ayzYV-7mv-5@gated-at.bofh.it>
     [not found] ` <ayA8E-89e-29@gated-at.bofh.it>
2008-05-28 20:37   ` optimizing out inline functions James Kosin
2008-05-29  3:27     ` Johannes Weiner
2008-05-29  3:04       ` Joe Perches
2008-05-29 13:11       ` James Kosin
2008-05-29 13:13       ` James Kosin
2008-05-28 19:51 Steve French
2008-05-28 19:54 ` Pekka Enberg
2008-05-29  8:40   ` Andrew Morton
2008-05-28 20:00 ` Sam Ravnborg
2008-05-29 16:39   ` Steve French
2008-05-29 17:20     ` Sam Ravnborg
2008-06-02  9:38     ` Vegard Nossum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox