fork(1) download
  1. #include <array>
  2. #include <cstring>
  3. #include <iostream>
  4.  
  5. struct Oops {
  6. char a;
  7. int b;
  8. };
  9.  
  10. void foo(std::array<char, 8>&) {
  11. }
  12. void (*foo_ptr)(std::array<char, 8>&) = foo;
  13.  
  14. bool __attribute__((noinline)) bar(Oops& o, char a, int b) {
  15. union {
  16. std::array<char, 8> x;
  17. Oops y;
  18. };
  19. x = {'P', 'o', 'p', 'a', 'p', 'o', 'p', 'a'};
  20. foo_ptr(x);
  21. y = {a, b};
  22. return std::memcmp(&o, &y, sizeof y) == 0;
  23. }
  24.  
  25. int main() {
  26. Oops a = {1, 2};
  27. if (bar(a, 1, 2)) {
  28. std::cout << "Everything's fine" << std::endl;
  29. } else {
  30. std::cout << "Someone's an idiot" << std::endl;
  31. }
  32. }
Success #stdin #stdout 0s 4476KB
stdin
Standard input is empty
stdout
Someone's an idiot