Re: Problem: __inline__ functions in the kernel & cli()/sti() latency measurement

Warner Losh (imp@village.org)
Tue, 11 Jun 1996 17:37:51 -0600


: Also, you can't return a value from a macro like that. You can
: from an inline function.
:
: Untrue:
:
: #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 :-)

a = val_plus_two( val )

would expand to

a = do { ((val) + 2); } while (0 );

which is illegal in C. gcc doesn't even have this extension and gives
a parse error at the "do" (at least for 2.6.3 and 2.7.2).

What your construct does do is make it safe to be used in an
"statement" context, but not an expression context.

While you can do very very very simple things that return a value, you
can't have a macro that walks a list and returns something out of the
middle of the list (unless you cunningly cached a pointer to it
somehow).

This, imho, is one of the flaws in the C language where it doesn't
quite hang right together.

Warner