Advertisement
Drainedsoul

Type Punning Solution

Apr 24th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. NBTTag& TagFloat::read(std::istream& stream) {
  2.    
  3.     static_assert(
  4.         sizeof(int32_t)==sizeof(float),
  5.         "Sizes of types are not appropriate!"
  6.     );
  7.    
  8.     union {
  9.         int32_t tmp;
  10.         float flt;
  11.     };
  12.    
  13.     stream.read(
  14.         reinterpret_cast<char *>(&tmp),
  15.         sizeof(int32_t)
  16.     );
  17.    
  18.     tmp=be32toh(tmp);
  19.    
  20.     payload=flt;
  21.    
  22.     return *this;
  23.    
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement