Guest User

Untitled

a guest
Feb 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. printf("Enter 0 to print hello and 1 to print goodbye: ");
  5. unsigned long mask = 0;
  6. scanf("%ld", &mask);
  7.  
  8. // ensure mask is 0 or 1
  9. mask = !(!(mask));
  10.  
  11. // extend first bit to all bits
  12. int i = 0;
  13. mask = mask|(mask << i++);
  14. mask = mask|(mask << i);
  15. i *= 2;
  16. mask = mask|(mask << i);
  17. i *= 2;
  18. mask = mask|(mask << i);
  19. i *= 2;
  20. mask = mask|(mask << i);
  21. i *= 2;
  22. mask = mask|(mask << i);
  23. i *= 2;
  24. mask = mask|(mask << i);
  25.  
  26. // Load the addresses of the labels. Only works in gcc.
  27. unsigned long h = (unsigned long) &&hello;
  28. unsigned long g = (unsigned long) &&goodbye;
  29.  
  30. // The mask is either all zeros or all ones, so this will evaulate to one of the addresses,
  31. // which is then passed to a parametric goto
  32. goto *(void *)((h&(~mask)) | (g&mask));
  33.  
  34. hello:
  35. printf("Hello!\n");
  36. goto end;
  37.  
  38. goodbye:
  39. printf("Goodbye!\n");
  40. goto end;
  41.  
  42. end:
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment