From 1b1c1299cf3b251a8ca61426e26da0fa9a79d238 Mon Sep 17 00:00:00 2001 From: Yury Kurlykov Date: Thu, 12 Dec 2019 02:05:26 +1000 Subject: [PATCH] Fix compilation error on big-endian machines --- inc/YeltsinDB/macro.h | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/inc/YeltsinDB/macro.h b/inc/YeltsinDB/macro.h index 1566ecd..4e0f9eb 100644 --- a/inc/YeltsinDB/macro.h +++ b/inc/YeltsinDB/macro.h @@ -31,27 +31,38 @@ */ #if BYTE_ORDER == BIG_ENDIAN +/* + * These inline functions are used for TO_LE and FROM_LE macros. + * The reason is a preprocessor can't include leXXtoh and htoleXX macros into them. + */ +static inline uint16_t __htole16(uint16_t x) { return htole16(x); } +static inline uint16_t __le16toh(uint16_t x) { return le16toh(x); } +static inline uint32_t __htole32(uint32_t x) { return htole32(x); } +static inline uint32_t __le32toh(uint32_t x) { return le32toh(x); } +static inline uint64_t __htole64(uint64_t x) { return htole64(x); } +static inline uint64_t __le64toh(uint64_t x) { return le64toh(x); } + #define TO_LE(x) _Generic((x), \ - uint16_t: htole16, \ - int16_t: htole16, \ - uint32_t: htole32, \ - int32_t: htole32, \ - uint64_t: htole64, \ - int64_t: htole64, \ + uint16_t: __htole16, \ + int16_t: __htole16, \ + uint32_t: __htole32, \ + int32_t: __htole32, \ + uint64_t: __htole64, \ + int64_t: __htole64 \ )(x) #define FROM_LE(x) _Generic((x), \ - uint16_t: le16toh, \ - int16_t: le16toh, \ - uint32_t: le32toh, \ - int32_t: le32toh, \ - uint64_t: le64toh, \ - int64_t: le64toh, \ + uint16_t: __le16toh, \ + int16_t: __le16toh, \ + uint32_t: __le32toh, \ + int32_t: __le32toh, \ + uint64_t: __le64toh, \ + int64_t: __le64toh \ )(x) -#define REASSIGN_FROM_LE(x) (x) = FROM_LE((x)) +#define REASSIGN_FROM_LE(x) (void)((x) = FROM_LE((x))) #else #define TO_LE(x) (x) #define FROM_LE(x) (x) #define REASSIGN_FROM_LE(x) -#endif \ No newline at end of file +#endif