fork download
  1. // We will ignore any warnings that we are using multi-character literals,
  2. // as using them is the whole point of this program
  3. #pragma GCC diagnostics ignored "-Wmultichar"
  4.  
  5. enum what {
  6. STOP = 'STOP',
  7. GO = ' GO',
  8. WAIT = 'WAIT'
  9. };
  10.  
  11. #include <iostream>
  12. static ::std::ostream& debug_print(::std::ostream& os, enum what x) {
  13. // We reinterpret_cast the values to show the same thing
  14. // a memory dump would show in the debugger:
  15. char const* p = reinterpret_cast<char const*>(&x);
  16. return os << p[3] << p[2] << p[1] << p[0];
  17. }
  18.  
  19. int main() {
  20. enum what stop = STOP;
  21. enum what go = GO;
  22. enum what wait = WAIT;
  23.  
  24. debug_print(::std::cout << "stop: ", stop) << "\n";
  25. debug_print(::std::cout << " go: ", go) << "\n";
  26. debug_print(::std::cout << "wait: ", wait) << "\n";
  27. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
stop: STOP
  go:   GO
wait: WAIT