[PATCH] Add getSwappedBytes implementations for float / double

Mehdi AMINI mehdi.amini at apple.com
Mon Jan 12 12:06:31 PST 2015


Because we are writing C++ and not C I tried to find what C++11 says about type punning:

"An lvalue expression of type T1 can be cast to the type “reference to T2” if an expression of type “pointer to T1” can be explicitly converted to the type “pointer to T2” using a reinterpret_cast. That is, a reference cast reinterpret_cast<T&>(x) has the same effect as the conversion *reinterpret_cast<T*>(&x) with the built-in & and * operators (and similarly for reinterpret_cast<T&&>(x)). The result refers to the same object as the source lvalue, but with a different type. The result is an lvalue for an lvalue reference type or an rvalue reference to function type and an xvalue for an rvalue reference to object type. No temporary is created, no copy is made, and constructors (12.1) or conversion functions (12.3) are not called."

So I assume this should be valid:

  return SwapByteOrder_64(reinterpret_cast<int &>(C));


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D6730

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list