Skip to content

Instantly share code, notes, and snippets.

@raek
Created September 8, 2016 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/738b6395d12bc1972fb6f05dea495969 to your computer and use it in GitHub Desktop.
Save raek/738b6395d12bc1972fb6f05dea495969 to your computer and use it in GitHub Desktop.
Puzzle of the Week #5: C'ing is believing
#include <stdio.h>
/* Run like this:
* gcc -Wall -Wextra puzzle5.c && ./a.out
*/
/* TODO: remove these weird unused functions */
long int g(long int x) {
return x;
}
typedef long int (*int_to_int)(long int);
int_to_int f(long int x) {
(void) x; /* unused */
return g;
}
/* Some "convenience" macros for "field" offsets */
#define ALPHA(f) ((long int) f + 0)
#define BETA (f) ((long int) f + 1)
#define GAMMA(f) ((long int) f + 2)
int main(int argc, char **argv)
{
long int values[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
long int field = 3;
(void) argc; /* unused */
(void) argv; /* unused */
printf("%ld, %ld, %ld\n",
values[ALPHA(field)],
values[BETA(field)],
values[GAMMA(field)]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment