https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102989

--- Comment #1 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
This also triggers the following wish:

'widthof(t)', which would be equivalent to 'sizeof(t) * CHAR_BIT' for normal
types, but would be equal to N in the case of _ExtInt(N).

It could also be used to mean the exact bit width of a bitfield.

This is helpful to have a generic TYPE_MAX(t) macro (yet another wish, although
this would be for glibc once widthof() is in GCC), which could be implemented
as:

#define ISSIGNED(t)    (((t) - 1) < 0)
#define __STYPE_MAX(t) (((((t) 1 << widthof(t) - 2)) - 1) << 1) + 1)
#define __UTYPE_MAX(t) ((t) -1)
#define TYPE_MAX(t)    (ISSIGNED(t) ? __STYPE_MAX(t) : __UTYPE_MAX(t))
#define TYPE_MIN(t)    ((t) ~TYPE_MAX(t))

These macros could be used for *any* integer type, including _ExtInt() and
bitfields, if the compiler provided widthof().

Reply via email to