Skip to content

Instantly share code, notes, and snippets.

@tlindner
Created February 7, 2022 16:15
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 tlindner/2f2b3aa10b874968afa2269667dc2b4d to your computer and use it in GitHub Desktop.
Save tlindner/2f2b3aa10b874968afa2269667dc2b4d to your computer and use it in GitHub Desktop.
/*
cmoc test program.
testing structs with function pointers
*/
#include <coco.h>
struct verb_noun_cmd
{
unsigned char verb;
unsigned char objNum;
unsigned char (*command)(void);
};
unsigned char cmd1(void)
{
printf("one\n");
return 1;
}
unsigned char cmd2(void)
{
printf("two\n");
return 2;
}
unsigned char cmd3(void)
{
printf("three\n");
return 3;
}
int main(void)
{
struct verb_noun_cmd cmds[] =
{
{0, 0, cmd1},
{1, 1, cmd2},
(2, 2, cmd3)
};
for( int i=0; i<3; i++ )
{
int j = cmds[i].command();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment