on Fri, 26 May 2023 23:20:37 +0600 you (NRK ) wrote: > On Fri, May 26, 2023 at 01:29:31PM +0200, Nat! wrote: > > I think it's sort of obvious, that these macros increase code > > brittleness due to now multiple execution of macro arguments vs. a > > single execution in a function call. > > It would be heavily surprising if the controlling expression of > _Generic was evaluated. Similar to `sizeof`, it only needs to know > the type of the expression and thus doesn't require evaluation (only > exception being VLAs in a sizeof). Yes, exactly, that's the idea. And VLA (and similar) are not allowed for the controling expression of a generic selection, so this problem does not arise, there. > | The controlling-expression and the expressions of the selections > that | are not chosen are never evaluated. > > However, there is one thing that I don't quite understand about this > patch: > > > + void const*: (void const*)bsearch((K), (void > > const*)(B), (N), (S), (C)), \ > > What's with the `(void const*)(B)` cast? It's already determined to be > `void const *` via _Generic. Even if not evaluated, all branches have to be syntactically and semantically correct. If you don't use these kind of casts, you may get a lot of warnings. This "feature" makes the use of these beast a bit subtle, sometimes. (Originally, generic selection had been designed to chose between different function pointers similar as in to implement something like overloading.) Thanks Jₑₙₛ -- :: ICube :::::::::::::::::::::::::::::: deputy director :: :: Université de Strasbourg :::::::::::::::::::::: ICPS :: :: INRIA Nancy Grand Est :::::::::::::::::::::::: Camus :: :: :::::::::::::::::::::::::::::::::::: ☎ +33 368854536 :: :: https://icube-icps.unistra.fr/index.php/Jens_Gustedt ::