5 ms·
It makes sense to have it in macros. Though standard C still doesn't have statement expressions, so...
by bonzini 4y ago
It makes sense to have it in macros. Though standard C still doesn't have statement expressions, so...
- dzaima 4y agoAs 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.
- afdbcreid 4y agoDo you really need to parenthesize the parameters? Is there something that can break the variable declaration into multiple statements?
- dzaima 4y agoHere, 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.
- kps 4y agoHere, no. It's just a habit or common style guideline to always parenthesize macro parameters since so many macros can otherwise break.
- peterfirefly 4y agoI wish ({...}) had been in C23.
- uecker 4y agoI agree, this is one of the more important common extensions we are still missing.
- peterfirefly 4y agoI'm still miffed it wasn't in C99 ;)
- uecker 4y agoSorry, 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.
- peterfirefly 4y agoYou 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.)
- uecker 4y agoIt is Sisyphean, but there also many synergies (I work on real-time computational imaging systems). And the specific things you mention were mostly not my work (I made typeof in GCC more coherent, which helped getting it standardized). But yes, I have a semi-complete C compiler around and many unfinished GCC branches...