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

Rich,

on Fri, 26 May 2023 16:09:42 -0400 you (Rich Felker <dalias@...c.org>)
wrote:

> I'll go ahead and follow up here rather than branching this thread
> elsewhere too: public headers are supposed to avoid creative content
> like comments. Once you remove the unneeded casts, comments, etc.
> these _Generics become much more compact and don't need the many-line,
> aligned-\ macro thing we don't generally do in musl.

Well, such a policy might be outdated. Nowadays compilers are quite
good in tracing errors back into macro defintions. Especially for
generic selection it is then really helpful for the user that they can
trace this down to a particular line of the macro that ideally
corresponds to exactly their selection that went wrong.

(Admittedly that's not a big deal here, yet, because this has only two
cases. But in general, when we have more of that stuff, having good
feedback from the compiler into the macro definition is very
valuable.)

> Could you elaborate on how such a warning could arise? bsearch (the
> function) takes const void *, and any object pointer type (assuming no
> other qualification like volatile on the pointed-to type) converts
> implicitly to const void *. So I don't think it's possible.

The `volatile` is indeed the problem here. If an application would do
that, without the cast they would see the error on the wrong
selection, which might be quite confusing.

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.