Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 26 May 2023 21:29:51 +0200
From: Jₑₙₛ Gustedt <jens.gustedt@...ia.fr>
To: NRK <nrk@...root.org>
Cc: musl@...ts.openwall.com
Subject: Re: [C23 const 1/2] C23: change bsearch to a macro that
 respects the const contract


on Fri, 26 May 2023 23:20:37 +0600 you (NRK <nrk@...root.org>) 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 <tgmath.h> 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 ::

Content of type "application/pgp-signature" skipped

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.