Messages in this thread |  | | From | (Richard Henderson) | Subject | Re: Problem: __inline__ functions in the kernel & cli()/sti() latency measurement | Date | Tue, 11 Jun 1996 23:26:45 -0500 (CDT) |
| |
> : #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~
|  |