Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230526172037.o2l4y63edb3k2n3n@gen2.localdomain>
Date: Fri, 26 May 2023 23:20:37 +0600
From: NRK <nrk@...root.org>
To: musl@...ts.openwall.com
Subject: Re: [C23 const 1/2] C23: change bsearch to a macro that
 respects the const contract

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).

And looking at cppreference, it seems that the controlling expression
indeed isn't evaluated: https://en.cppreference.com/w/c/language/generic#Notes

| 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.

- NRK

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.