]> git.ozlabs.org Git - ccan/commitdiff
endian: Wrap arguments in braces to silence warnings
authorJoel Stanley <joel@jms.id.au>
Thu, 14 Aug 2014 03:37:53 +0000 (13:37 +1000)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 15 Aug 2014 18:23:56 +0000 (03:53 +0930)
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@jms.id.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/endian/endian.h

index 02f5a68baf02adf94a1bcfd308c8f0a577accc48..dc9f62e646df471d3341cedd6db2f5e2928cff36 100644 (file)
@@ -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.
  *     };
  */
 #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.
  *     };
  */
 #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>