News for hackers. Stuff that matters.
Re:Show HN: Cppmatch – Rust-Like Pattern Matching and Error ... by senkora on Sunday March 16, 2025 @10:12PM (#43384555)
Have you considered using the immediately invoked function expression (IIFE) pattern as a standards-compliant alternative to gcc statement expressions?
Re:Show HN: Cppmatch – Rust-Like Pattern Matching and Error ... by Rucadi on Monday March 17, 2025 @03:06AM (#43385868)
The main problem with IIFE is the same as with a normal function:

You cannot return the caller function from inside the closure, making the "short-circuit" mechanism provided by questionmark (?) operator not possible.

With the GCC Extension, we get around that using a construct that is pretty similar to IIFE, it allows to return a value from an immediate expression created by a block of code that is surrounded by ({})

The nice thing about this block ({}) is that the last statement is used as the "return value" without an explicit return, this disambiguates between the "expression" return and the "function" return.

Without compiler support, the short-circit is not possible, but with this feature + macros we can create a function that behaves like that.

Re:Show HN: Cppmatch – Rust-Like Pattern Matching and Error ... by Rucadi on Monday March 17, 2025 @03:25AM (#43385980)
Regardless of that, the only function that requires this extension is the "except" macro, if you are willing to not short-circuit, you can still use the other functionality of this library.
Re:Show HN: Cppmatch – Rust-Like Pattern Matching and Error ... by senkora on Tuesday March 18, 2025 @05:28PM (#43405366)
Makes sense, thank you!