From: Martin Uecker > Sent: 07 December 2024 21:06 > > Am Samstag, dem 07.12.2024 um 21:00 +0000 schrieb David Laight: > > From: Martin Uecker > > > Sent: 07 December 2024 19:52 > ... > > > > > > There exist proposals along those lines for C2Y. > > > > > > From a more near-term solution, I wonder if making it possible (or > > > easier) to return integer constant expressions from statement > > > expressions and allowing a restricted form of statement expressions > > > at file scope would help? > > > > It would help a lot if a #define that just used local variables > > to avoid arguments being re-expanded and for CSE could still > > generate a constant value. > > Does need to be a #define - to get token pasting and 'stringify'. > > Although you would need something for reporting detected errors, > > and builtin compiler support for const_true() for the detection > > itself. > > We are super close: > > https://godbolt.org/z/Tarq89bha (The preprocess output is about 500 bytes for each line.) > (if we ignore the grotesque hacks to get there, but this would go > away if the compiler does it internally) Some of those hacks look excessive. Isn't IF_CONST(x, y, z) just _Generic(0 ? (void *)((x) ? 0L : 0L) : (char *)0, char *: y, void *: z) and that gets rid some of the grossness. Just having that as a builtin would simplify some things. Although you could use: __builtin_choose_expr(IS_CONST(x), y, z) if you need y and z to have different types, and just: IS_CONST(x) ? y : z otherwise. Since AFAICT they are otherwise equivalent. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)