Hacker News new | ask | show | jobs
by bonzini 1138 days ago
It makes sense to have it in macros. Though standard C still doesn't have statement expressions, so...
1 comments

As an example of this, a generic `MAX` macro that doesn't evaluate its arguments multiple times, would be (using said GNU extension of statement expressions):

    #define MAX(A, B) ({ auto a = (A); auto b = (B); a>b? a : b; })
As-is, for such things I just use __auto_type, as it's already in the GNU-extension-land.
Do you really need to parenthesize the parameters? Is there something that can break the variable declaration into multiple statements?
Here, no. It's just a habit or common style guideline to always parenthesize macro parameters since so many macros can otherwise break.
Here, probably not (with proper arguments at least; without the parens something like `MAX(1;2, 3)` would compile without errors though), but I'm just used to doing it everywhere.
I wish ({...}) had been in C23.
I agree, this is one of the more important common extensions we are still missing.
I'm still miffed it wasn't in C99 ;)
Sorry, it was on my list of things to propose, but I did not have enough time (due to a job change). Others were more interested in lambdas.
You are forgiven. It must be like pushing water up a mountain. At least we got #embed, typeof, auto, constexpr, and sensible enums this time around.

How many of you guys have half of a C compiler lying around in a directory somewhere on your machines?

(And how do you find the time for WG14 AND writing code AND doing research? My cousin is in roughly the same field as you and you publish more than he does.)