This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: [jbaron@redhat.com: [PATCH 0/3] tracepoints: delay argument evaluation]
- From: Andrew Haley <aph at redhat dot com>
- To: Jason Baron <jbaron at redhat dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 20 May 2009 15:15:46 +0100
- Subject: Re: [jbaron@redhat.com: [PATCH 0/3] tracepoints: delay argument evaluation]
- References: <20090520135631.GA3081@redhat.com>
[Redirected to gcc-help]
Jason Baron wrote:
> While working on some Linux kernel code, I've found that functions that
> are declared as 'static inline' are having their arguments evaluated
> well before they are used. For example I have a function:
>
> static inline void trace(arg1, arg2)
> {
> if (unlikely(enabled)) {
> <use the arguments>
> }
> }
>
> If i call 'trace(ptr->arg1, ptr->arg2)', then the pointers are
> dereferenced before the 'if' is executed. Is there any way to delay the
> argument evaluation until they are used?
I don't think so. Expanding this inline function is the same as
arg1 = ptr->arg1;
arg2 = ptr->arg2;
if (unlikely(enabled)) {
<use the arguments>
}
You want a macro:
#define trace(arg1, arg2) \
{ \
if (unlikely(enabled)) { \
<use the arguments> \
} \
Andrew.