#include <stdio.h>
#include <stdlib.h>
// Define the functions
int func1() {
printf("This is function 1\n");
return 1;
}
void func2() {
printf("This is function 2\n");
}
float func3() {
printf("This is function 3\n");
return 3.14;
}
// Define a union for possible return types
typedef union {
int i;
float f;
void *v;
} ReturnType;
// Define an enum for the return types
typedef enum {
INT,
VOID,
FLOAT
} ReturnTypeID;
// Define a struct to store the function pointer and its type
typedef struct {
void *func;
ReturnTypeID type;
} FuncEntry;
// Function signatures
typedef int (*FuncPtr1)();
typedef void (*FuncPtr2)();
typedef float (*FuncPtr3)();
// Function call handler
ReturnType callFunc(FuncEntry entry) {
ReturnType result;
switch (entry.type) {
case INT:
result.i = ((FuncPtr1)entry.func)();
break;
case VOID:
((FuncPtr2)entry.func)();
result.v = NULL;
break;
case FLOAT:
result.f = ((FuncPtr3)entry.func)();
break;
}
return result;
}
int main() {
// Array of function entries
FuncEntry functions[] = {
{func1, INT},
{func2, VOID},
{func3, FLOAT}
};
int size = sizeof(functions) / sizeof(functions[0]);
for (int i = 0; i < size; i++) {
ReturnType ret = callFunc(functions[i]);
// Handle the return value based on type
switch (functions[i].type) {
case INT:
printf("Return value: %d\n", ret.i);
break;
case VOID:
printf("No return value\n");
break;
case FLOAT:
printf("Return value: %.2f\n", ret.f);
break;
}
}
return 0;
}