Hi Bruno,

On 2026-02-21T01:18:40+0100, Bruno Haible wrote:
> Alejandro Colomar wrote:
> >     #define __QVoidptrof(p)  typeof(1?(p):(void*){0})
> > 
> >     #define __QCharptrof(s)  typeof                               \
> >     (                                                             \
> >            _Generic((__QVoidptrof(s)){0},                         \
> >                    const void *: (const char *) 0,                \
> >                    void *:       (char *) 0                       \
> >            )                                                      \
> >     )
> > 
> >     #if __STDC_VERSION__ >= 202311L
> >     # define memchr(p, chr)    ((__QVoidptrof(p)) memchr(p, chr))
> >     # define strchr(s, chr)    ((__QCharptrof(s)) strchr(s, chr))
> >     # define strrchr(s, chr)   ((__QCharptrof(s)) strrchr(s, chr))
> >     # define strpbrk(s, chrs)  ((__QCharptrof(s)) strpbrk(s, chrs))
> >     # define strstr(s, str)    ((__QCharptrof(s)) strstr(s, str))
> >     #endif
> > 
> > I find it quite more readable than the glibc implementation.
> 
> Sorry, but I disagree on this "more readable" claim. You take an aggregate
> initializer {0} and cast that to 'void *'. What is that meant to be??

That's a compound literal (a C99 feature).
<https://www.geeksforgeeks.org/c/compound-literals-c/>

> Additionally, there are situations where '_Generic' works and 'typeof'
> doesn't (namely clang-cl in C++ mode).
> 
> So, I vote for a simple use of _Generic.
> 
> > I think it would be more reasonable to transform all string APIs to be
> > const-generic at once
> 
> This is outside the scope of Gnulib. Making strchr etc. const-generic
> is the job of the system include files, and is important only on the
> developer's main development machine (for getting warnings). It would
> be a big effort with little value to make this work on all older
> platforms, from AIX to Solaris.

Should we then just make strnul() consistent with all other string APIs
and thus not const-generic?  I'd be surprised if a libc implementation
provided const-generic macros for some APIs but not for others.


Have a lovely night!
Alex

> 
> Bruno
> 
> 
> 

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

Attachment: signature.asc
Description: PGP signature

Reply via email to