headers/intsafe: Add missing MIN/MAX macros.

I tested this with my test suite at
https://github.com/DavidEGrayson/intsafe
to make sure the values and types are correct in
32-bit/64-bit MinGW and 64-bit Cygwin environments.

Potential compatibility issues:
- The types of smaller macros like UINT8_MAX are 'int',
  which is different from Microsoft's intsafe.h, but follows the
  C specification and allows the preprocessor to understand
  the macro's numeric value.
- LONG_MIN, LONG_MAX, and ULONG_MAX describe 'long' and 'unsigned long',
  whereas native Windows code might expect them to describe
  LONG and ULONG, which sometimes have a different size.
- 128-bit macros from the Microsoft header are not yet supported.
- Some of these definitions are different than what we have in
  stdint.h, limits.h, and cfgmgr32.h, so I'd like to submit a patch
  for those later if this is acceptd.

To keep things consistent and simple, I followed these rules:
- A macro does not refer to another macro unless it saves a line of code.
  Chains of macros are hard to debug because other included headers
  could break the chain by redefining any macro in the chain.
- Only use decimal if it makes the number shorter (otherwise use hex).
- Don't use uppercase hex digits.
- Don't use uppercase suffixes (for compatibility with __MSABI_LONG).
- Only use 'l' and 'll' suffixes if necessary.
- Use a 'u' suffix on any unsigned macro that has a 'l' or 'll' suffix,
  to make it clear what the type is.
- Use a 'u' suffix on any macro describing an unsigned type with
  32 bits or more.  This ensures those macros will be treated as
  unsigned in the preprocessor, avoiding surprising situations where
  macros with the same value like ULONG_MAX and UINT32_MAX are
  treated differently.
- Only use subtraction if necessary.

Signed-off-by: David Grayson <davidegrayson@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
1 file changed