How do you use Function Pointer in Struct? Specifically, given the following example, the program compiles but crash on run-time:
In a header file
 #ifndef __FUNCTION_IN_STRUCT_H_
 #define __FUNCTION_IN_STRUCT_H_
struct functionDaemon {
     int id;
     //double (*funcp); // function pointer
     double  (*fp)(double);      // Function pointer
 };
 // #define NULL 'V'
 #endif /* _FUNCTION_IN_STRUCT_H_ */
In the C file:
#include <math.h>
#include <stdio.h>
#include "function_in_struct.h"
extern struct functionDaemon *ftnAgent;
void do_compute_sum (void) {
     void* agent;
    // struct functionDaemon *ftnAgent = (struct functionDaemon *) agent;
    struct functionDaemon *ftnAgent;
    double  sum;
    // Use 'sin()' as the pointed-to function
    ftnAgent->fp = sin;
    sum = compute_sum(ftnAgent->fp, 0.0, 1.0);
    printf("sum(sin): %f\n", sum);
}
Please advise me.
 
    