fork(3) download
  1. // Experiment based on answer from
  2. // http://stackoverflow.com/questions/573294/when-to-use-reinterpret-cast
  3. // by sfinktah bungholio
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main() {
  9. // One use of reinterpret_cast is if you want to apply bitwise operations to
  10. // (IEEE 754) floats. For instance:
  11.  
  12. double d = 64;
  13.  
  14. printf("d: %0.4d\n",
  15. reinterpret_cast<double&>((reinterpret_cast<int64_t&>(d) >> 1) + (1L << 61))
  16. );
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:15:74: warning: left shift count >= width of type [-Wshift-count-overflow]
  reinterpret_cast<double&>((reinterpret_cast<int64_t&>(d) >> 1) + (1L << 61))
                                                                          ^
prog.cpp:15:77: error: invalid cast of an rvalue expression of type 'int64_t {aka long long int}' to type 'double&'
  reinterpret_cast<double&>((reinterpret_cast<int64_t&>(d) >> 1) + (1L << 61))
                                                                             ^
stdout
Standard output is empty