lkml.org 
[lkml]   [1996]   [Jun]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: Problem: __inline__ functions in the kernel & cli()/sti() latency measurement
Date
> : #define val_plus_two(val) do { ((val) + 2); } while(0)
> :
> : It still does not annul the multi-evaluation reasoning for using
> : inline functions instead of macros though ;-)
>
> No, your assertion is untrue :-)

There is a gcc extention that does it though:

#define val_plus_two(val) ({ val + 2; })

or less trivially

#define fib(x) \
({ __typeof(x) __x = (x), __n0 = 0, __n1 = 0, __n2 = 0, __i; \
for (__i = 0; __i < __x; ++__i) { \
__typeof(x) __t = __n1 + __n0; \
__n0 = __n1; \
__n1 = __n2; \
__n2 = __t; \
}
__n2;
})

which calculates the result in the input type and has no problems
with re-evaluation of the input arguments.

The only problem is that the variables are not statically scoped.

It is, however, good for when the "function" needs to change its
return type or the specifics of the situation demand that the
function is inlined whether optimization is on or not.


r~


\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.327 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site