comparison Core/Endianness.h @ 2706:0511feaf0ec2

fix for LSB
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 06 Jul 2018 16:48:48 +0200
parents 6d5e36e1256f
children 38a3054b22ff
comparison
equal deleted inserted replaced
2705:5c18a22cb981 2706:0511feaf0ec2
143 143
144 #include <stdint.h> 144 #include <stdint.h>
145 145
146 static inline uint16_t __orthanc_bswap16(uint16_t a) 146 static inline uint16_t __orthanc_bswap16(uint16_t a)
147 { 147 {
148 return (a << 8) | (a >> 8); 148 const uint8_t* p = reinterpret_cast<const uint8_t*>(&a);
149 return (static_cast<uint32_t>(p[0]) << 8 |
150 static_cast<uint32_t>(p[1]));
151
152 // WARNING: The implementation below makes LSB (Linux Standard
153 // Base) segfault in release builds. Don't use it!!!
154 // return (a << 8) | (a >> 8);
149 } 155 }
150 156
151 static inline uint32_t __orthanc_bswap32(uint32_t a) 157 static inline uint32_t __orthanc_bswap32(uint32_t a)
152 { 158 {
153 const uint8_t* p = reinterpret_cast<const uint8_t*>(&a); 159 const uint8_t* p = reinterpret_cast<const uint8_t*>(&a);