[vlc-commits] bswap64: hack for C++ brain damage

Rémi Denis-Courmont git at videolan.org
Thu Aug 18 21:17:52 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Aug 18 22:17:12 2011 +0300| [67fc58a5e7b4ee34c72138d703c815e25dd7ce2f] | committer: Rémi Denis-Courmont

bswap64: hack for C++ brain damage

Contrary to C, C++ compilers don't promote larger constants up to
unsigned long long when needed.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=67fc58a5e7b4ee34c72138d703c815e25dd7ce2f
---

 include/vlc_common.h |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index 9e49c35..1da9ea9 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -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
 }
 



More information about the vlc-commits mailing list