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

Linus Torvalds (torvalds@linux.cs.helsinki.fi)
Wed, 12 Jun 1996 08:51:27 +0300 (EET DST)


On Tue, 11 Jun 1996, Warner Losh wrote:
>
> Also, you can't reutrn a value from a macro like that. You can from
> an inline function.

GNU C _does_ allow you to return a value from a C macro, and I think it's
even used by Linux someplace:

#define MACRO_RETURNS_ARG(x) ({ \
int __temp_value = x; \
printf("returning %d\n", __temp_value); \
__temp_value; \
})

The "({ .. })" syntax is a "block expression", and the last statement in
the block is the value of the whole expression. ("__tmp_value" used here
to get the "x" evaluated only once - you can use other gcc extensions
like "__typeof__" to do more generic macros)

It's sometimes useful, but most of the time it's just plain stupid to use
it, because it only works with gcc (when it comes to the kernel that's
ok, but..)

Linus