]> git.sesse.net Git - vlc/commitdiff
bswap64: hack for C++ brain damage
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 18 Aug 2011 19:17:12 +0000 (22:17 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 18 Aug 2011 19:17:12 +0000 (22:17 +0300)
Contrary to C, C++ compilers don't promote larger constants up to
unsigned long long when needed.

include/vlc_common.h

index 9e49c35fb09638d7fce8a5140e6b459e73d6d455..1da9ea950f4e865fea7bca65ecfb082bced5dcac 100644 (file)
@@ -657,7 +657,7 @@ static inline uint64_t bswap64 (uint64_t x)
 {
 #if VLC_GCC_VERSION(4,3)
     return __builtin_bswap64 (x);
-#else
+#elif !defined (__cplusplus)
     return ((x & 0x00000000000000FF) << 56)
          | ((x & 0x000000000000FF00) << 40)
          | ((x & 0x0000000000FF0000) << 24)
@@ -666,6 +666,15 @@ static inline uint64_t bswap64 (uint64_t x)
          | ((x & 0x0000FF0000000000) >> 24)
          | ((x & 0x00FF000000000000) >> 40)
          | ((x & 0xFF00000000000000) >> 56);
+#else
+    return ((x & 0x00000000000000FFLLU) << 56)
+         | ((x & 0x000000000000FF00LLU) << 40)
+         | ((x & 0x0000000000FF0000LLU) << 24)
+         | ((x & 0x00000000FF000000LLU) <<  8)
+         | ((x & 0x000000FF00000000LLU) >>  8)
+         | ((x & 0x0000FF0000000000LLU) >> 24)
+         | ((x & 0x00FF000000000000LLU) >> 40)
+         | ((x & 0xFF00000000000000LLU) >> 56);
 #endif
 }