Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a macro that expands to return without parentheses?

I want to use a macro like this

#define  Return(x)   {call_my_function(); return (x);}

is there any way to use or declare a macro without parentheses, so I can use it like a real return call and not a function? For example:

BOOL my_func() {
    code....
    Return FALSE;
}
like image 219
Tibor Avatar asked Aug 08 '12 12:08

Tibor


People also ask

What is argumented macro in C?

Function-like macros can take arguments, just like true functions. To define a macro that uses arguments, you insert parameters between the pair of parentheses in the macro definition that make the macro function-like. The parameters must be valid C identifiers, separated by commas and optionally whitespace.

Why do we recommend the use of parentheses for formal arguments used in a macro definition?

The macro and its parameters should be enclosed in parentheses. When macro parameters or expression are not parenthesized, the intended logic may get disrupted after expanding the macro.


1 Answers

You could do something horrific as

#define  Return for (call_my_function(); ;) return

Edit: Changed to Daniel's version for the nice smiley that makes. And Jim's idea of "overloading" return directly is valid and even more horrific ;)

like image 62
Jens Gustedt Avatar answered Sep 20 '22 17:09

Jens Gustedt