Messages in this thread | | | Subject | Re: optimizing out inline functions | From | Joe Perches <> | Date | Wed, 28 May 2008 20:04:22 -0700 |
| |
On Thu, 2008-05-29 at 05:27 +0200, Johannes Weiner wrote: > James Kosin <jkosin@beta.intcomgrp.com> writes: > >> But we do not have KCONFIG_DEBUG_SOMETHING available > >> so the second best is to use an empty function > >> to keep the typechecking in place. > >> IIRC gcc optimize both away. > > Another way would be to have: > > static inline void some_debug_function(var1) > > { > > #ifdef KCONFIG_DEBUG_SOMETHING > > something = var1; > > printk(some debug text); > > #endif > > }
A potential issue is a possible unnecessary call of any function used as an argument to some_debug_function.
int unnecessary_debug_test(void) { int foo; [] return foo; }
static inline void some_debug_function(int bar) { }
some_debug_function(unnecessary_debug_test())
unnecessary_debug_test will still get called
Macro wrappers/statement expressions can be used to avoid the function call. see kernel.h/pr_debug for an example.
#ifdef DEBUG /* If you are writing a driver, please use dev_dbg instead */ #define pr_debug(fmt, arg...) \ printk(KERN_DEBUG fmt, ##arg) #else #define pr_debug(fmt, arg...) \ ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; }) #endif
| |