Skip to content

Instantly share code, notes, and snippets.

@wrl
Created June 20, 2017 21:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wrl/f441772e7e62dfe7ed1b5cd15fcb2882 to your computer and use it in GitHub Desktop.
Save wrl/f441772e7e62dfe7ed1b5cd15fcb2882 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
#define MAX 100
int
main(int argc, char **argv)
{
intptr_t op[MAX + 2];
int ip;
void *compile_ops[8] = {
[0] = &&op_print,
[1] = &&op_fizz,
[2] = &&op_buzz,
[3] = &&op_fizzbuzz,
[4 ... 7] = &&op_done
};
for (ip = 0; ip < MAX + 2; ip++)
op[ip] = (intptr_t) compile_ops[
(!(ip % 3))
| ((!(ip % 5)) << 1)
| ((ip > MAX) << 2)
];
ip = 0;
#define NEXT goto *op[++ip]
op_print: printf("%d\n", ip); NEXT;
op_fizz: puts("fizz"); NEXT;
op_buzz: puts("buzz"); NEXT;
op_fizzbuzz: puts("fizzbuzz"); NEXT;
op_done:
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment