Elektrine lite

← Feed

@thephd@pony.social

Post #2813114

2026-05-11 13:42 UTC

@simontatham@hachyderm.io It was more of an implementation peculiarity than anything else, really. Internally, we check if what is coming in is a modifiable lvalue and -- if it is -- take a reference to it. Unfortunately the way we were doing it before took a reference to the stripped-down type if certain kinds of pointers got involved, and this wrecked parsing a little bit. But that part's been fixed and the modifiable lvalue bit is only taken later.

Replies (1)

  • @simontatham@hachyderm.io 2026-05-11 13:59

    @thephd@pony.social Out of interest, what's your best recommendation for writing a _Generic that switches on two of its operand types, if the choices aren't independent and there's no default clause? In my 2023 article I mentioned the idea of using a function type to stand in for a type tuple, via GNU typeof, along the lines of _Generic((void (*)(__typeof(x), __typeof(y)))NULL, void (*)(int, int) : "got two ints", void (*)(int, char *) : "got an int and a string", void (*)(char *, int) : "got a string and an int") Now that typeof is standard in C23, that idea doesn't depend on GNU extensions any more. And it's certainly an improvement on the horrible system of integer type ids I suggested as a workaround at the time. But do you have any even better ideas? Ideally, a way to combine it with the N3888 identifiers, so as to be able to get both good features at once – the ability to switch on both types, _and_ the ability to refer to both values inside the branch via correctly typed identifiers?

    Open ##2813115