streq(), wcseq(): New functions to compare strings for equality
Alejandro Colomar
alx@kernel.org
Fri Aug 29 17:15:42 GMT 2025
On Fri, Aug 29, 2025 at 07:14:15PM +0200, Alejandro Colomar wrote:
> Hi Collin,
>
> On Fri, Aug 29, 2025 at 10:03:38AM -0700, Collin Funk wrote:
> > Wilco Dijkstra <Wilco.Dijkstra@arm.com> writes:
> >
> > > That's a lot of extra overhead, so most people would continue using
> > >
> > > #define streq(X,Y) strcmp(X,Y) == 0
> > >
> > > as that's simpler and faster.
> >
> > I don't think it is too much of an issue to write this in projects if
> > they want them personally:
> >
> > static inline bool
> > streq (char const *a, char const *b)
> > {
> > return ! strcmp (a, b);
> > }
> >
> > static inline bool
> > strneq (char const *a, char const *b)
> > {
> > return !! strcmp (a, b);
> > }
BTW, please don't do this. strn*() are functions that handle
[[gnu::nonstring]] things. We should not confuse programmers with yet
another inconsistent name. The opposite of streq() should be !streq().
Cheers,
Alex
>
> Once you start wrapping every other libc API that is imperfect, you end
> up having your own string library with somewhere around 30 or 40
> functions. And at that point, given that every project has their
> slightly different names and slightly different function prototypes,
> contributors don't know what to expect from the code.
>
> That's why having a system string library is a good thing. Everybody
> talks the same language.
>
> After all, I don't think it is too much of an issue to write the same
> inline function in glibc, once and for all.
>
>
> Have a lovely day!
> Alex
>
> >
> > Collin
>
> --
> <https://www.alejandro-colomar.es>
> Use port 80 (that is, <...:80/>).
--
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250829/3529facd/attachment.sig>
More information about the Libc-alpha
mailing list