refined some endian conversion macros with proper type casting

This commit is contained in:
hyunghwan.chung 2019-05-03 03:20:26 +00:00
parent 409aa7befe
commit f1850b2a94

View File

@ -842,76 +842,77 @@ static MOO_INLINE moo_uint128_t moo_bswap128 (moo_uint128_t x)
#if defined(MOO_ENDIAN_LITTLE) #if defined(MOO_ENDIAN_LITTLE)
# if defined(MOO_HAVE_UINT16_T) # if defined(MOO_HAVE_UINT16_T)
# define moo_ntoh16(x) moo_bswap16(x)
# define moo_hton16(x) moo_bswap16(x) # define moo_hton16(x) moo_bswap16(x)
# define moo_ntoh16(x) moo_bswap16(x)
# define moo_htobe16(x) moo_bswap16(x) # define moo_htobe16(x) moo_bswap16(x)
# define moo_htole16(x) (x)
# define moo_be16toh(x) moo_bswap16(x) # define moo_be16toh(x) moo_bswap16(x)
# define moo_le16toh(x) (x) # define moo_htole16(x) ((moo_uint16_t)(x))
# define moo_le16toh(x) ((moo_uint16_t)(x))
# endif # endif
# if defined(MOO_HAVE_UINT32_T) # if defined(MOO_HAVE_UINT32_T)
# define moo_ntoh32(x) moo_bswap32(x)
# define moo_hton32(x) moo_bswap32(x) # define moo_hton32(x) moo_bswap32(x)
# define moo_ntoh32(x) moo_bswap32(x)
# define moo_htobe32(x) moo_bswap32(x) # define moo_htobe32(x) moo_bswap32(x)
# define moo_htole32(x) (x)
# define moo_be32toh(x) moo_bswap32(x) # define moo_be32toh(x) moo_bswap32(x)
# define moo_le32toh(x) (x) # define moo_htole32(x) ((moo_uint32_t)(x))
# define moo_le32toh(x) ((moo_uint32_t)(x))
# endif # endif
# if defined(MOO_HAVE_UINT64_T) # if defined(MOO_HAVE_UINT64_T)
# define moo_ntoh64(x) moo_bswap64(x)
# define moo_hton64(x) moo_bswap64(x) # define moo_hton64(x) moo_bswap64(x)
# define moo_ntoh64(x) moo_bswap64(x)
# define moo_htobe64(x) moo_bswap64(x) # define moo_htobe64(x) moo_bswap64(x)
# define moo_htole64(x) (x)
# define moo_be64toh(x) moo_bswap64(x) # define moo_be64toh(x) moo_bswap64(x)
# define moo_le64toh(x) (x) # define moo_htole64(x) ((moo_uint64_t)(x))
# define moo_le64toh(x) ((moo_uint64_t)(x))
# endif # endif
# if defined(MOO_HAVE_UINT128_T) # if defined(MOO_HAVE_UINT128_T)
# define moo_ntoh128(x) moo_bswap128(x)
# define moo_hton128(x) moo_bswap128(x) # define moo_hton128(x) moo_bswap128(x)
# define moo_ntoh128(x) moo_bswap128(x)
# define moo_htobe128(x) moo_bswap128(x) # define moo_htobe128(x) moo_bswap128(x)
# define moo_htole128(x) (x)
# define moo_be128toh(x) moo_bswap128(x) # define moo_be128toh(x) moo_bswap128(x)
# define moo_le128toh(x) (x) # define moo_htole128(x) ((moo_uint128_t)(x))
# define moo_le128toh(x) ((moo_uint128_t)(x))
# endif # endif
#elif defined(MOO_ENDIAN_BIG) #elif defined(MOO_ENDIAN_BIG)
# if defined(MOO_HAVE_UINT16_T) # if defined(MOO_HAVE_UINT16_T)
# define moo_ntoh16(x) (x) # define moo_hton16(x) ((moo_uint16_t)(x))
# define moo_hton16(x) (x) # define moo_ntoh16(x) ((moo_uint16_t)(x))
# define moo_htobe16(x) (x) # define moo_htobe16(x) ((moo_uint16_t)(x))
# define moo_be16toh(x) ((moo_uint16_t)(x))
# define moo_htole16(x) moo_bswap16(x) # define moo_htole16(x) moo_bswap16(x)
# define moo_be16toh(x) (x)
# define moo_le16toh(x) moo_bswap16(x) # define moo_le16toh(x) moo_bswap16(x)
# endif # endif
# if defined(MOO_HAVE_UINT32_T) # if defined(MOO_HAVE_UINT32_T)
# define moo_ntoh32(x) (x) # define moo_hton32(x) ((moo_uint32_t)(x))
# define moo_hton32(x) (x) # define moo_ntoh32(x) ((moo_uint32_t)(x))
# define moo_htobe32(x) (x) # define moo_htobe32(x) ((moo_uint32_t)(x))
# define moo_be32toh(x) ((moo_uint32_t)(x))
# define moo_htole32(x) moo_bswap32(x) # define moo_htole32(x) moo_bswap32(x)
# define moo_be32toh(x) (x)
# define moo_le32toh(x) moo_bswap32(x) # define moo_le32toh(x) moo_bswap32(x)
# endif # endif
# if defined(MOO_HAVE_UINT64_T) # if defined(MOO_HAVE_UINT64_T)
# define moo_ntoh64(x) (x) # define moo_hton64(x) ((moo_uint64_t)(x))
# define moo_hton64(x) (x) # define moo_ntoh64(x) ((moo_uint64_t)(x))
# define moo_htobe64(x) (x) # define moo_htobe64(x) ((moo_uint64_t)(x))
# define moo_be64toh(x) ((moo_uint64_t)(x))
# define moo_htole64(x) moo_bswap64(x) # define moo_htole64(x) moo_bswap64(x)
# define moo_be64toh(x) (x)
# define moo_le64toh(x) moo_bswap64(x) # define moo_le64toh(x) moo_bswap64(x)
# endif # endif
# if defined(MOO_HAVE_UINT128_T) # if defined(MOO_HAVE_UINT128_T)
# define moo_ntoh128(x) (x) # define moo_hton128(x) ((moo_uint128_t)(x))
# define moo_hton128(x) (x) # define moo_ntoh128(x) ((moo_uint128_t)(x))
# define moo_htobe128(x) (x) # define moo_htobe128(x) ((moo_uint128_t)(x))
# define moo_be128toh(x) ((moo_uint128_t)(x))
# define moo_htole128(x) moo_bswap128(x) # define moo_htole128(x) moo_bswap128(x)
# define moo_be128toh(x) (x)
# define moo_le128toh(x) moo_bswap128(x) # define moo_le128toh(x) moo_bswap128(x)
# endif # endif