'Return value from macro without gcc braced groups
If i have a macro that looks like that:
#define some_macro(x,y,z)({
operation1;
operation2;
...;
x+y+z; //return value
})
how can i make it return value without using gcc braced groups ({})? I also can't add any other arguments to the macro. I'm getting this compiler message:
warning: ISO C forbids braced-groups within expressions [-Wpedantic]
But i need the code to be portable, not only for gcc.
Solution 1:[1]
You can use the comma operator which allows multiple expressions to be combined to a single one. This is more restrictive than GCC statement expressions (which may contain variable declarations, for, while, switch, etc), but the comma operator works if operation1 and operation2 and the rest are expressions.
#define some_macro(x,y,z) (operation1, operation2, (x)+(y)+(z))
If this does not work you could define a function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
