Paul Eggert wrote:
> I suggest looking how glibc implements the qualifier-generic strchr 
> macro for C, and doing something similar. See glibc commit 
> cd748a63ab1a7ae846175c532a3daab341c62690 dated 2025-11-20.

See also the code in gnulib/lib/string-desc.h which determines whether
_Generic is available:

/* Whether the compiler supports _Generic.
   Test program:
     int f (int x) { return _Generic (x, char *: 2, int: 3); }
 */
#if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined 
__cplusplus) /* C mode */ \
    || (defined __clang__ && __clang_major__ >= 3) /* both C and C++ mode */ \
    || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) /* C mode */ \
    || (__STDC_VERSION__ >= 201112L && !defined __GNUC__) /* C mode */
# define HAVE__GENERIC 1
#endif

Bruno




Reply via email to