A “hack” to get float template parameter working compiles but segfaulted on both g++ and clang
I know why I can't use float as template parameter and how to set a static const float member of template class thanks to a numerator/denominator couple. But I was trying another "hack" based on reinterpret_cast to "emule" float template parameters from its IEEE754 hexadecimal writing. Here is the small piece of code : #include <iostream> #include <cstdint> template <uint32_t T> struct MyStruct { static const float value; }; template <uint32_t T> const float MyStruct<T>::value = *reinterpret_cast<float*>(T); int main() { typedef MyStruct<0x40490fdb> Test; std::cout << Test::value << std::endl;