Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- printf("Enter 0 to print hello and 1 to print goodbye: ");
- unsigned long mask = 0;
- scanf("%ld", &mask);
- // ensure mask is 0 or 1
- mask = !(!(mask));
- // extend first bit to all bits
- int i = 0;
- mask = mask|(mask << i++);
- mask = mask|(mask << i);
- i *= 2;
- mask = mask|(mask << i);
- i *= 2;
- mask = mask|(mask << i);
- i *= 2;
- mask = mask|(mask << i);
- i *= 2;
- mask = mask|(mask << i);
- i *= 2;
- mask = mask|(mask << i);
- // Load the addresses of the labels. Only works in gcc.
- unsigned long h = (unsigned long) &&hello;
- unsigned long g = (unsigned long) &&goodbye;
- // The mask is either all zeros or all ones, so this will evaulate to one of the addresses,
- // which is then passed to a parametric goto
- goto *(void *)((h&(~mask)) | (g&mask));
- hello:
- printf("Hello!\n");
- goto end;
- goodbye:
- printf("Goodbye!\n");
- goto end;
- end:
- return 0;
- }
Add Comment
Please, Sign In to add comment