Skip to content

Instantly share code, notes, and snippets.

@rkujawa
Created August 2, 2016 14:26
Show Gist options
  • Save rkujawa/352fcc7d70197764af5c60bf16a3b677 to your computer and use it in GitHub Desktop.
Save rkujawa/352fcc7d70197764af5c60bf16a3b677 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
struct code_data {
uint8_t len;
char *name;
};
struct code_data commands[] = {
{0, "noop"}, /* 0 */
{0, "foobar"},
{2, "thing-taking-two-args"},
{10, "omgthisishuge"} /* 3 */
/* ... */
};
void print_command(uint8_t c)
{
printf("command %d : %s taking %d args\n", c, commands[c].name,
commands[c].len );
}
int main(int argc, char *argv[])
{
print_command(0);
print_command(1);
print_command(2);
print_command(3);
}
/*
command 0 : noop taking 0 args
command 1 : foobar taking 0 args
command 2 : thing-taking-two-args taking 2 args
command 3 : omgthisishuge taking 10 args
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment