[ccan] [PATCH] endian: Wrap arguments in braces to silence warnings
Joel Stanley
joel at jms.id.au
Thu Aug 14 13:37:53 EST 2014
When using the endian swapping marcos with multiple arguments that are
or'd together:
CPU_TO_BE64(THIS_THING | THAT_THING)
gcc will emit this warning:
warning: suggest parentheses around arithmetic in operand
of ‘|’ [-Wparentheses]
Wrap the arugments in braces to avoid this.
Signed-off-by: Joel Stanley <joel at jms.id.au>
---
ccan/endian/endian.h | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/ccan/endian/endian.h b/ccan/endian/endian.h
index 02f5a68..dc9f62e 100644
--- a/ccan/endian/endian.h
+++ b/ccan/endian/endian.h
@@ -16,8 +16,8 @@
* };
*/
#define BSWAP_16(val) \
- ((((uint16_t)val & 0x00ff) << 8) \
- | (((uint16_t)val & 0xff00) >> 8))
+ ((((uint16_t)(val) & 0x00ff) << 8) \
+ | (((uint16_t)(val) & 0xff00) >> 8))
/**
* BSWAP_32 - reverse bytes in a constant uint32_t value.
@@ -31,10 +31,10 @@
* };
*/
#define BSWAP_32(val) \
- ((((uint32_t)val & 0x000000ff) << 24) \
- | (((uint32_t)val & 0x0000ff00) << 8) \
- | (((uint32_t)val & 0x00ff0000) >> 8) \
- | (((uint32_t)val & 0xff000000) >> 24))
+ ((((uint32_t)(val) & 0x000000ff) << 24) \
+ | (((uint32_t)(val) & 0x0000ff00) << 8) \
+ | (((uint32_t)(val) & 0x00ff0000) >> 8) \
+ | (((uint32_t)(val) & 0xff000000) >> 24))
/**
* BSWAP_64 - reverse bytes in a constant uint64_t value.
@@ -48,14 +48,14 @@
* };
*/
#define BSWAP_64(val) \
- ((((uint64_t)val & 0x00000000000000ffULL) << 56) \
- | (((uint64_t)val & 0x000000000000ff00ULL) << 40) \
- | (((uint64_t)val & 0x0000000000ff0000ULL) << 24) \
- | (((uint64_t)val & 0x00000000ff000000ULL) << 8) \
- | (((uint64_t)val & 0x000000ff00000000ULL) >> 8) \
- | (((uint64_t)val & 0x0000ff0000000000ULL) >> 24) \
- | (((uint64_t)val & 0x00ff000000000000ULL) >> 40) \
- | (((uint64_t)val & 0xff00000000000000ULL) >> 56))
+ ((((uint64_t)(val) & 0x00000000000000ffULL) << 56) \
+ | (((uint64_t)(val) & 0x000000000000ff00ULL) << 40) \
+ | (((uint64_t)(val) & 0x0000000000ff0000ULL) << 24) \
+ | (((uint64_t)(val) & 0x00000000ff000000ULL) << 8) \
+ | (((uint64_t)(val) & 0x000000ff00000000ULL) >> 8) \
+ | (((uint64_t)(val) & 0x0000ff0000000000ULL) >> 24) \
+ | (((uint64_t)(val) & 0x00ff000000000000ULL) >> 40) \
+ | (((uint64_t)(val) & 0xff00000000000000ULL) >> 56))
#if HAVE_BYTESWAP_H
#include <byteswap.h>
--
2.1.0.rc1
More information about the ccan
mailing list