#include <stdio.h>
#include "C:/MediaFiles/File/STUDY/P1/Structure Function Pointer/Manager.h"
void callFunctionCall_addFun(int a,int b);
void callFunctionCall_subsFun(int a,int b);
void callFunctionCall_divideFun(int a,int b);
void callFunctionCall_modeFun(int a,int b);
FunctionCall* FunctionCall_GetInterface(void);
FunctionCall callFunctionCall =
{
callFunctionCall_addFun,
callFunctionCall_subsFun,
callFunctionCall_divideFun,
callFunctionCall_modeFun
};
FunctionCall* FunctionCall_GetInterface(void)
{
printf("FunctionCall_GetInterface --> Called\n");
return &callFunctionCall;
}
void callFunctionCall_addFun(int a,int b)
{
printf("callFunctionCall_addFun --> Called\n");
printf("Add of %d and %d is: %d\n",a,b,(a+b));
}
void callFunctionCall_subsFun(int a,int b)
{
printf("callFunctionCall_subsFun --> Called\n");
printf("Subtract of %d and %d is: %d\n",a,b,(a-b));
}
void callFunctionCall_divideFun(int a,int b)
{
printf("callFunctionCall_divideFun --> Called\n");
printf("Divide of %d and %d is: %d\n",a,b,(a/b));
}
void callFunctionCall_modeFun(int a,int b)
{
printf("callFunctionCall_modeFun --> Called\n");
printf("Mode of %d and %d is: %d\n",a,b,(a%b));
}
int main(void)
{
FunctionCall *mainCall= FunctionCall_GetInterface();
printf("%x\n",*mainCall);
return 0;
}
и Manager.h
#include <stdint.h>
typedef struct FunctionCall{
void (*addFun)(int a,int b);
void (*subsFun)(int a,int b);
void (*divideFun)(int a,int b);
void (*modeFun)(int a,int b);
} FunctionCall;