#include <stdio.h>
#include <assert.h>
typedef unsigned char byte;
typedef byte (*smbusCallback)(byte*);
byte exampleCallback(byte* buff) {
buff[0] = 1;
return 1;
}
byte (* funMap [])(byte*) = {
exampleCallback,
NULL
};
byte buffGlobal[50];
byte doCommand(byte command) {
smbusCallback func = funMap[command];
if (func == NULL) {
printf("callback was null with command %i\n", command);
return 0;
} else {
printf("callback was a function with command %i\n", command);
}
return func(buffGlobal);
}
int main() {
int len = -1;
len = doCommand(0);
assert (len == 1);
assert (buffGlobal[0] == 1);
len = doCommand(1);
assert (len == 0);
return 0;
}