Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.std.c |
| Subject | Re: Can the new generic string functions accept void* arguments? |
| Date | Fri, 02 Jun 2023 15:11:30 -0700 |
| Organization | None to speak of |
| Lines | 50 |
| Message-ID | <87zg5hecq5.fsf@nosuchdomain.example.com> (permalink) |
| References | <87fs7afpcw.fsf@nosuchdomain.example.com> <87bkhyfnm7.fsf@nosuchdomain.example.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | dont-email.me; posting-host="5b657b82d13cddbb6cd3c00c59757abe"; logging-data="3474396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zJX/VVvL01spn45fcVLkf" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
| Cancel-Lock | sha1:U3WYydPMQUbOftQklUavEyNE640= sha1:Wx4L9dOvpmRatniOayE0Q4GHjiw= |
| Xref | csiph.com comp.std.c:6493 |
Show key headers only | View raw
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> The latest draft of the upcoming C23 standard is:
>> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
>> It introduces several type-generic functions in <string.h>, replacing
>> normal functions of the same names: memchr, strchr, strpbrk, strrchr,
>> strstr.
>>
>> I'll use strchr() as an example; the same applies to the other str*()
>> generic functions (but not to memchr()).
> [...]
>
> Just after I posted the above, I thought of a potential issue with
> memchr() that just might affect real code.
[snip]
And I think I've found an even more serious issue with bsearch().
In C17 and earlier, bsearch() is declared as:
void *bsearch(const void *key, const void *base,
size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
`base` points to the object being searched. The returned value is a
pointer to non-const void pointing to an element of the searched object.
C23 (as of N3096) has:
QVoid *bsearch(const void *key, QVoid *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
where QVoid is either void or const void, depending on the type of the
base argument.
The obvious implementation using _Generic will reject a base argument of
a type other than `void* or `const void*`.
(I see Ben posted a followup with a possible solution. I haven't
studied it yet.)
I've been discussing this by email with the editors (listed on the first
page of N3096).
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.std.c | Previous | Next — Previous in thread | Find similar | Unroll thread
Can the new generic string functions accept void* arguments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-01 21:41 -0700
Re: Can the new generic string functions accept void* arguments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-01 22:18 -0700
Re: Can the new generic string functions accept void* arguments? Jakob Bohm <jb-usenet@wisemo.com.invalid> - 2023-06-02 15:03 +0200
Re: Can the new generic string functions accept void* arguments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-02 11:52 -0700
Re: Can the new generic string functions accept void* arguments? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-02 22:01 +0100
Re: Can the new generic string functions accept void* arguments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-04 21:37 -0700
Re: Can the new generic string functions accept void* arguments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-04 21:50 -0700
Re: Can the new generic string functions accept void* arguments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-02 15:11 -0700
csiph-web