在 2026-2-18 03:45, David Grayson 写道:
I'm trying to compile a Windows program that uses DWORD_MAX, so I'm working
on adding missing definitions like that to MinGW's intsafe.h.  Microsoft's
intsafe.h explicitly defines *MIN/*MAX macros so they have the type they
were named after (e.g. UINT8_MAX is a UINT8).

However, our stdint.h, and many other open-source implementations
implicitly define UINT8_MAX, INT8_MIN, INT8_MAX, UINT16_MAX, INT16_MIN, and
INT16_MAX to have type int.

Microsoft SDK intsafe.h:        #define UINT8_MAX       0xffui8
Microsoft SDK icu.h:            #   define UINT8_MAX       ((uint8_t)(255U))
Microsoft SDK icucommon.h:      #   define UINT8_MAX       ((uint8_t)(255U))

mingw-w64-headers/crt/stdint.h: #define UINT8_MAX 255
mingw-w64-tools/widl:           #define UINT8_MAX              (255U)
gcc-15.2.0/fixinclues:          #define UINT8_MAX       (255)
musl stdint.h:                  #define UINT8_MAX  (0xff)
glibc:                          # define UINT8_MAX            (255)

GCC's builtin __UINT8_MAX__ has type int (as evidenced by the error message
from compiling "char * x = __UINT8_MAX__").

The 2nd and 3rd ones can't be used in `#if`. The pre-processor doesn't know `uint8_t` and replaces it with 0, and then the syntax becomes invalid. So those are not standard-compliant.


To me it makes more sense if UINT8_MAX is an UINT8, not an int.  But if we
want it to be an int, that's fine.  In that case, for consistency, I would
make BYTE_MAX, INT8_MIN, INT8_MAX, UINT16_MAX, USHORT_MAX, WORD_MAX,
INT16_MIN, INT16_MAX, SHORT_MIN, and SHORT_MAX all be int.
Right. Unfortunately there's no standard suffix to specify a type below `int` 
or `unsigned int`.


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to