From: Alejandro Colomar <alx@kernel.org>
To: linux-man@vger.kernel.org
Subject: QChar and QVoid for strchr(3), memchr(3), et al.
Date: Tue, 24 Feb 2026 15:28:41 +0100 [thread overview]
Message-ID: <aZ2xBQcy7mMEXW_b@devuan> (raw)
[-- Attachment #1: Type: text/plain, Size: 2414 bytes --]
Hi!
ISO C23 changed the specification of string search functions so that if
the const qualifier is present in the input, the APIs preserve it in the
output.
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf#subsection.7.26.5>
For example, memchr(3) and strchr(3) were previously specified as
alx@devuan:~$ stdc C11 memchr
void *memchr(const void *s, int c, size_t n);
alx@devuan:~$ stdc C11 strchr
char *strchr(const char *s, int c);
They are now specified as
QVoid *memchr(QVoid *s, int c, size_t n);
QChar *strchr(QChar *s, int c);
The new specification is only possible through macros, and only in
calls. Function pointers such as &memchr or &strchr, or calls that
avoid the macro, such as (memchr)(p,0) or (strchr)(s,0), do not use the
macro, and as such, still use the old function prototype. However, the
ability to do this is declared obsolescent by both ISO C and the glibc
manual. This means that the underlying functions might eventually be
removed from the headers.
glibc has implemented the C23 specification in glibc-2.43, in commit
glibc.git cd748a63ab1a (2025-11-20; "Implement C23 const-preserving standard library macros").
I've written a patch for musl, but it hasn't been applied yet:
<https://www.openwall.com/lists/musl/2026/02/23/1>
gnulib has recently added a new search function, strnul(3) --which we
already document in a manual page--, and didn't include an underlying
function, since it didn't make sense to add something already obsolete.
I documented the strnul(3) API as if it were a set of C++ overloads:
char *strnul(char *s);
const char *strnul(const char *s);
Now that I'm considering the documentation of the glibc changes, I'm
wondering what's the most appropriate way to document them. I have
a few questions:
- In the SYNOPSIS, do you prefer QChar/QVoid or overload style?
QChar *strchr(QChar *s, int c);
vs
char *strnul(char *s);
const char *strnul(const char *s);
- If we document it as QChar/QVoid, I guess we should we add a
QChar(3)/QVoid(3) manual page documenting all of the details, to
avoid duplicating such details in each manual page.
- How much should we document the old function? Should we keep that as
a historic detail in the QChar(3)/QVoid(3) page?
Any other comments?
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2026-02-24 14:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 14:28 Alejandro Colomar [this message]
2026-02-24 16:56 ` QChar and QVoid for strchr(3), memchr(3), et al Mark Harris
2026-02-24 17:14 ` Paul Eggert
2026-02-24 21:31 ` Alejandro Colomar
2026-02-24 23:04 ` Paul Eggert
2026-02-24 23:05 ` Alejandro Colomar
2026-02-24 23:19 ` Paul Eggert
2026-02-24 23:34 ` Alejandro Colomar
2026-02-25 1:03 ` Mark Harris
2026-02-25 1:15 ` Alejandro Colomar
2026-02-24 18:52 ` Rene Kita
2026-02-24 21:41 ` Alejandro Colomar
2026-02-25 15:48 ` Rene Kita
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=aZ2xBQcy7mMEXW_b@devuan \
--to=alx@kernel.org \
--cc=linux-man@vger.kernel.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox