2424 * builtins for GCC. MSVC has similar ones. 
2525 */  
2626
27- #if  defined(WIN32)
27+ //  Some GCC versions do not include __builtin_bswap16
28+ //  The compiler optimizes the code below into a single ROL instruction so the intrinsic is not really needed
29+ #define  BYTESWAP16 (v ) (((v) >> 8 ) | ((v) << 8 ))
30+ 
31+ #if  defined(WIN32) || defined(_WIN32)
2832 #define  BSWAP16 (b,v ) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : _byteswap_ushort((::uint16_t )v))
2933 #define  BSWAP32 (b,v ) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : _byteswap_ulong((::uint32_t )v))
3034 #define  BSWAP64 (b,v ) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : _byteswap_uint64((::uint64_t )v))
3135#elif  __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
32-  #define  BSWAP16 (b,v ) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : __builtin_bswap16 ((::uint16_t )v))
36+  #define  BSWAP16 (b,v ) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : BYTESWAP16 ((::uint16_t )v))
3337 #define  BSWAP32 (b,v ) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : __builtin_bswap32((::uint32_t )v))
3438 #define  BSWAP64 (b,v ) ((b == Ir::SBE_LITTLE_ENDIAN) ? (v) : __builtin_bswap64((::uint64_t )v))
3539#elif  __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
36-  #define  BSWAP16 (b,v ) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : __builtin_bswap16 ((::uint16_t )v))
40+  #define  BSWAP16 (b,v ) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : BYTESWAP16 ((::uint16_t )v))
3741 #define  BSWAP32 (b,v ) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : __builtin_bswap32((::uint32_t )v))
3842 #define  BSWAP64 (b,v ) ((b == Ir::SBE_BIG_ENDIAN) ? (v) : __builtin_bswap64((::uint64_t )v))
3943#else 
@@ -44,11 +48,11 @@ using namespace sbe::on_the_fly;
4448using  ::std::cout;
4549using  ::std::endl;
4650
47- #if  !defined(WIN32)
51+ #if  defined(WIN32) || defined(_WIN32)
52+ #define  snprintf  _snprintf
53+ #else 
4854const  ::int32_t  Field::INVALID_ID;
4955const  int  Field::FIELD_INDEX;
50- #else 
51- #define  snprintf  _snprintf
5256#endif  /*  WIN32 */ 
5357
5458Listener::Listener () : onNext_(NULL ), onError_(NULL ), onCompleted_(NULL ),
@@ -112,14 +116,14 @@ int Listener::subscribe(OnNext *onNext,
112116 {
113117 char  message[1024 ];
114118
115-  ::snprintf (message, sizeof (message)-1, "no IR found for message with templateId=%ld and version=%ld", templateId_, templateVersion_);
119+  ::snprintf (message, sizeof (message)-1, "no IR found for message with templateId=%ld and version=%ld [E117] ", templateId_, templateVersion_);
116120 onError_->onError (Error (message));
117121 result = -1 ;
118122 }
119123 }
120124 else  if  (onError_ != NULL )
121125 {
122-  onError_->onError (Error (" template ID and/or version not found in header"  ));
126+  onError_->onError (Error (" template ID and/or version not found in header [E118] "  ));
123127 result = -1 ;
124128 }
125129 }
0 commit comments