[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <524f69650805290939v65f9f5b8m65fd1ba23acd08d8@mail.gmail.com>
Date: Thu, 29 May 2008 11:39:32 -0500
From: "Steve French" <smfrench@...il.com>
To: "Sam Ravnborg" <sam@...nborg.org>
Cc: lkml <linux-kernel@...r.kernel.org>
Subject: Re: optimizing out inline functions
Ran into one loosely related question, printk takes a variable
argument list, so the calling function in this case would also need to
be able to handle thos variable arguments. With macros, we are able
to do things like with variable arguments easily
#define function_to_print_some_warning(format, arg...)
printk(KERN_WARNING ": " format "\n" , ## arg)
Are there style rules (or nicely written examples) for doing this
(variable argument lists) with (inline) functions
On Wed, May 28, 2008 at 3:00 PM, Sam Ravnborg <sam@...nborg.org> wrote:
> On Wed, May 28, 2008 at 02:51:02PM -0500, Steve French wrote:
>> 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
>
> With reference to a recent thread about kconfig
> I would prefer:
> static inline void some_debug_function(var1)
> {
> if (KCONFIG_DEBUG_SOMETHING) {
> something = var1;
> printk(some debug text);
> }
> }
>
>
> 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.
>
> Sam
>
--
Thanks,
Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists