Re: [PATCH v3 5/5] string: Make strprefix() const-qualifier-generic

From: Alejandro Colomar

Date: Wed Nov 11 2026 - 06:28:53 EST


Hi David,

> Date: 2026-11-11 10:34:38+0000
> From: David Laight <david.laight.linux@xxxxxxxxx>
>
[...]
> > -static inline char *strprefix(const char *s, const char *prefix)
> > +#define strprefix(s, pfx) const_cast(CQChar_of(s) *, strprefix(s, pfx))
>
> Isn't in enough to do:
> #define strprefix(s, pfx) ((typeof(s))strprefix(s, pfx))
>
> which correctly preserves all qualifiers.

This would return a const void* if you pass a const void*. In general,
we shouldn't be passing a void* to a string function, but C allows this.
With CQChar_of(), you coerce a 'const void *' into a 'const char *'.

See also: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3998.pdf#subsection.0.7.28.5>


Cheers,
Alex

--
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature