|
@ -22,9 +22,9 @@ int sub(int a, int b); |
|
|
//int err(int a, int b); |
|
|
//int err(int a, int b); |
|
|
void err(void); |
|
|
void err(void); |
|
|
int operation(t_fptr_op op, int a, int b); |
|
|
int operation(t_fptr_op op, int a, int b); |
|
|
t_fptr_op select(char opc); |
|
|
|
|
|
|
|
|
t_fptr_op select(int opc); |
|
|
void initialiseOperationsArray(void); |
|
|
void initialiseOperationsArray(void); |
|
|
int evalArray(char opc, int a, int b); |
|
|
|
|
|
|
|
|
int evalArray(int opc, int a, int b); |
|
|
t_fptr_op operations[128] = {NULL}; |
|
|
t_fptr_op operations[128] = {NULL}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -87,7 +87,7 @@ int square(int num) { |
|
|
|
|
|
|
|
|
// function selector |
|
|
// function selector |
|
|
// returns pointer to selected function |
|
|
// returns pointer to selected function |
|
|
t_fptr_op select(char opc) { |
|
|
|
|
|
|
|
|
t_fptr_op select(int opc) { |
|
|
switch (opc) { |
|
|
switch (opc) { |
|
|
case '+': return add; |
|
|
case '+': return add; |
|
|
case '-': return sub; |
|
|
case '-': return sub; |
|
@ -104,7 +104,7 @@ void err(void) { //int a, int b) { |
|
|
|
|
|
|
|
|
// evaluate given operation on a & b |
|
|
// evaluate given operation on a & b |
|
|
// operation is given by function pointer |
|
|
// operation is given by function pointer |
|
|
int eval(char opc, int a, int b) { |
|
|
|
|
|
|
|
|
int eval(int opc, int a, int b) { |
|
|
t_fptr_op operation = select(opc); |
|
|
t_fptr_op operation = select(opc); |
|
|
return operation(a, b); |
|
|
return operation(a, b); |
|
|
} |
|
|
} |
|
@ -120,7 +120,7 @@ void initialiseOperationsArray(void) { |
|
|
|
|
|
|
|
|
// eval function which works with |
|
|
// eval function which works with |
|
|
// the array of function pointers |
|
|
// the array of function pointers |
|
|
int evalArray(char opc, int a, int b) { |
|
|
|
|
|
|
|
|
int evalArray(int opc, int a, int b) { |
|
|
t_fptr_op operation; |
|
|
t_fptr_op operation; |
|
|
operation = operations[opc]; |
|
|
operation = operations[opc]; |
|
|
return operation(a, b); |
|
|
return operation(a, b); |
|
|