Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| 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 | 2023-06-02 15:11 -0700 |
| Organization | None to speak of |
| Message-ID | <87zg5hecq5.fsf@nosuchdomain.example.com> (permalink) |
| References | <87fs7afpcw.fsf@nosuchdomain.example.com> <87bkhyfnm7.fsf@nosuchdomain.example.com> |
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