mailing list of musl libc
 help / color / mirror / code / Atom feed
From: NRK <nrk@disroot.org>
To: musl@lists.openwall.com
Subject: Re: [musl] [C23 const 1/2] C23: change bsearch to a macro that respects the const contract
Date: Fri, 26 May 2023 23:20:37 +0600	[thread overview]
Message-ID: <20230526172037.o2l4y63edb3k2n3n@gen2.localdomain> (raw)
In-Reply-To: <3a4f4a8e-9179-6606-e449-6fc2812d3525@mulle-kybernetik.com>

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

  reply	other threads:[~2023-05-26 17:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 14:44 [musl] [C23 const 0/2] some interfaces become type-generic Jens Gustedt
2023-05-25 14:44 ` [musl] [C23 const 1/2] C23: change bsearch to a macro that respects the const contract Jens Gustedt
2023-05-26 11:29   ` Nat!
2023-05-26 17:20     ` NRK [this message]
2023-05-26 19:29       ` Jₑₙₛ Gustedt
2023-05-26 20:09         ` Rich Felker
2023-05-27  7:51           ` Jₑₙₛ Gustedt
2023-05-25 14:45 ` [musl] [C23 const 2/2] C23: change string.h and wchar.h interfaces to macros " Jens Gustedt
     [not found] <cover.1685541439.git.Jens.Gustedt@inria.fr>
2023-05-31 14:00 ` [musl] [C23 const 1/2] C23: change bsearch to a macro " Jens Gustedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230526172037.o2l4y63edb3k2n3n@gen2.localdomain \
    --to=nrk@disroot.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).