Created
February 7, 2022 16:15
-
-
Save tlindner/2f2b3aa10b874968afa2269667dc2b4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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