Re:-fbounds-safety: Enforcing bounds safety for C
by uecker on Thursday February 19, 2026 @09:56AM
(#47074453)
Or just do it in C.
https://godbolt.org/z/TvxseshGc
[ Parent
| on HN ]
Re:-fbounds-safety: Enforcing bounds safety for C
by nananana9 on Thursday February 19, 2026 @10:38AM
(#47074964)
Still requires a gcc/clang specific extension (although this one I'd be very happy to see standardized)
Re:-fbounds-safety: Enforcing bounds safety for C
by uecker on Thursday February 19, 2026 @01:04PM
(#47076864)
Only statement expressions, but one can also implement this without them.
Re:-fbounds-safety: Enforcing bounds safety for C
by nananana9 on Friday February 20, 2026 @02:46AM
(#47084951)
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.
Re:-fbounds-safety: Enforcing bounds safety for C
by uecker on Friday February 20, 2026 @05:24AM
(#47086109)
You are not happy with immediately invoked lambda expressions?
Re:-fbounds-safety: Enforcing bounds safety for C
by nananana9 on Friday February 20, 2026 @06:29AM
(#47086658)
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.
Re:-fbounds-safety: Enforcing bounds safety for C
by uecker on Friday February 20, 2026 @07:54AM
(#47087411)
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++.
Re:-fbounds-safety: Enforcing bounds safety for C
by fuhsnn on Thursday February 19, 2026 @11:34AM
(#47075605)
The fact that pointer types can't be used with this pattern without typedef still seems kinda primitive to me.
Re:-fbounds-safety: Enforcing bounds safety for C
by uecker on Thursday February 19, 2026 @01:06PM
(#47076887)
You can use pointer types by using a typedef first, but I agree this not nice (I hope we will fix this in future C). But then, I think this is a minor inconvenience for having an otherwise working span type in C.