Hi all,
Is it possible to use a function pointer "pointing" to a macro which expands to the actual function?
Look at the following dummy code:
Until now I just called the functions Abstr_0_SendData() and Abstr_1_SendData() directly, now I rewrote the code to call them via a function pointer configured in the myconfig var, is this somehow possible? It gives me some errors, see below.
Code:
#include <stdio.h>
#define Abstr_0_SendData(data) SendData(0, data)
#define Abstr_1_SendData(data) SendData(1, data)
typedef void (*fptr)(int data);
//typedef void (*fptr)(int type, int data); // 2nd fptr try
typedef struct
{
int type;
fptr my_fkt;
} config;
void SendData(int type, int data)
{
printf("SendData: %d, %d\n", type, data);
}
int main ()
{
int i;
config myconfig[2] =
{ { 10, &Abstr_0_SendData }
, { 20, &Abstr_1_SendData }
};
for (i = 0; i < 2; i++) {
myconfig[i].my_fkt(99);
// int type = myconfig[i].type;
// myconfig[i].my_fkt(type, 99); // 2nd fptr try
}
return 0;
}
which results in:
main.c: In function `main':
main.c:25: error: `Abstr_0_SendData' undeclared (first use in this function)
main.c:25: error: (Each undeclared identifier is reported only once
main.c:25: error: for each function it appears in.)
main.c:26: error: `Abstr_1_SendData' undeclared (first use in this function)