Added min/max macros for the sized SDL datatypes
authorSam Lantinga <slouken@libsdl.org>
Mon, 16 Oct 2017 14:39:56 -0700
changeset 1162797bc026b46de
parent 11626 2eaf345a2a30
child 11628 81a4950907a0
Added min/max macros for the sized SDL datatypes
include/SDL_stdinc.h
test/testplatform.c
     1.1 --- a/include/SDL_stdinc.h	Sun Oct 15 21:21:19 2017 -0700
     1.2 +++ b/include/SDL_stdinc.h	Mon Oct 16 14:39:56 2017 -0700
     1.3 @@ -146,35 +146,51 @@
     1.4  /**
     1.5   * \brief A signed 8-bit integer type.
     1.6   */
     1.7 +#define SDL_MAX_SINT8   ((Sint8)0x7F)           /* 127 */
     1.8 +#define SDL_MIN_SINT8   ((Sint8)(~0x7F))        /* -128 */
     1.9  typedef int8_t Sint8;
    1.10  /**
    1.11   * \brief An unsigned 8-bit integer type.
    1.12   */
    1.13 +#define SDL_MAX_UINT8   ((Uint8)0xFF)           /* 255 */
    1.14 +#define SDL_MIN_UINT8   ((Uint8)0x00)           /* 0 */
    1.15  typedef uint8_t Uint8;
    1.16  /**
    1.17   * \brief A signed 16-bit integer type.
    1.18   */
    1.19 +#define SDL_MAX_SINT16  ((Sint16)0x7FFF)        /* 32767 */
    1.20 +#define SDL_MIN_SINT16  ((Sint16)(~0x7FFF))     /* -32768 */
    1.21  typedef int16_t Sint16;
    1.22  /**
    1.23   * \brief An unsigned 16-bit integer type.
    1.24   */
    1.25 +#define SDL_MAX_UINT16  ((Uint16)0xFFFF)        /* 65535 */
    1.26 +#define SDL_MIN_UINT16  ((Uint16)0x0000)        /* 0 */
    1.27  typedef uint16_t Uint16;
    1.28  /**
    1.29   * \brief A signed 32-bit integer type.
    1.30   */
    1.31 +#define SDL_MAX_SINT32  ((Sint32)0x7FFFFFFF)    /* 2147483647 */
    1.32 +#define SDL_MIN_SINT32  ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
    1.33  typedef int32_t Sint32;
    1.34  /**
    1.35   * \brief An unsigned 32-bit integer type.
    1.36   */
    1.37 +#define SDL_MAX_UINT32  ((Uint32)0xFFFFFFFFu)   /* 4294967295 */
    1.38 +#define SDL_MIN_UINT32  ((Uint32)0x00000000)    /* 0 */
    1.39  typedef uint32_t Uint32;
    1.40  
    1.41  /**
    1.42   * \brief A signed 64-bit integer type.
    1.43   */
    1.44 +#define SDL_MAX_SINT64  ((Sint64)0x7FFFFFFFFFFFFFFFll)      /* 9223372036854775807 */
    1.45 +#define SDL_MIN_SINT64  ((Sint64)(~0x7FFFFFFFFFFFFFFFll))   /* -9223372036854775808 */
    1.46  typedef int64_t Sint64;
    1.47  /**
    1.48   * \brief An unsigned 64-bit integer type.
    1.49   */
    1.50 +#define SDL_MAX_UINT64  ((Uint64)0xFFFFFFFFFFFFFFFFull)     /* 18446744073709551615 */
    1.51 +#define SDL_MIN_UINT64  ((Uint64)(0x0000000000000000ull))   /* 0 */
    1.52  typedef uint64_t Uint64;
    1.53  
    1.54  /* @} *//* Basic data types */
     2.1 --- a/test/testplatform.c	Sun Oct 15 21:21:19 2017 -0700
     2.2 +++ b/test/testplatform.c	Mon Oct 16 14:39:56 2017 -0700
     2.3 @@ -30,6 +30,26 @@
     2.4  {
     2.5      int error = 0;
     2.6  
     2.7 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
     2.8 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
     2.9 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
    2.10 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
    2.11 +
    2.12 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
    2.13 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
    2.14 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
    2.15 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
    2.16 +
    2.17 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
    2.18 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
    2.19 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
    2.20 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
    2.21 +
    2.22 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
    2.23 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
    2.24 +	SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
    2.25 +	SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
    2.26 +
    2.27      if (badsize(sizeof(Uint8), 1)) {
    2.28          if (verbose)
    2.29              SDL_Log("sizeof(Uint8) != 1, instead = %u\n",