Paul Eggert wrote:
> +# define _GL_TYPE_SIGNED(t) \
> +   (_Generic ((t) {0}, \
> +              bool: 0, char: CHAR_MIN < 0, signed char: 1, unsigned char: 0, 
> \
> +              short int: 1, unsigned short int: 0, int: 1, unsigned int: 0, \
> +              long int: 1, unsigned long int: 0, long long int: 1, unsigned 
> long long int: 0, \
> +              float: 1, double: 1, long double: 1))

1) What about implementation-defined integer types, such as __int128 [1]?

2) I've come to dislike _Generic, because it does not work in C++ mode
(except in clang++):

/* 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

I.e. everywhere where one uses _Generic in a .h file, one needs to test
__cplusplus and use templates for the C++ case.

Bruno

[1] https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/_005f_005fint128.html




Reply via email to