I don't use much C but if you add them to the standard they'll probably trickle down to C++ compilers by 2045 and I'll have a good 10 years to use them before I retire.
Well, I'll take them over the nothing you're giving me :D
But in all seriousness, I want this:
struct Result { int value; int err; };
#define TRY(res) \
({ \
Result _res = res; \
if (failed(res)) return res; \
res.value; \
})
Result f1(...) { ... }
Result f2() {
int res = TRY(f1(...)); // <<<<
...
return success();
}
Can't be done with lambdas since the macro needs to return out of the actual function, not the lambda. Pretty much rust question mark, but without rust, or zig "try" but without zig.
I see, thanks! There is general consensus that statement expressions should become part of ISO C, but some lack of time to get it done. I am not part of WG21 though, so can't say anything about C++.
Only statement expressions, but one can also implement this without them.
Still, please standardize them :).
I don't use much C but if you add them to the standard they'll probably trickle down to C++ compilers by 2045 and I'll have a good 10 years to use them before I retire.
You are not happy with immediately invoked lambda expressions?
Well, I'll take them over the nothing you're giving me :D
But in all seriousness, I want this:
Can't be done with lambdas since the macro needs to return out of the actual function, not the lambda. Pretty much rust question mark, but without rust, or zig "try" but without zig.I see, thanks! There is general consensus that statement expressions should become part of ISO C, but some lack of time to get it done. I am not part of WG21 though, so can't say anything about C++.