The following example crashes when I call the member that is pointing to a function.
You don't call a member function because you have not yet assigned one.
#include <stdio.h>
#include <stdlib.h>
typedef long fooPtr(char *);
typedef struct
{
fooPtr *func;
long cnt;
} MyStruct;
/******************************************************************************/
long func(char * str)
{
printf("%s\n", str);
return -1;
}
/******************************************************************************/
int main(void)
{
long l = 0;
MyStruct *ex = malloc(sizeof *ex);
if ( ex != NULL )
{
ex->func = func;
ex->cnt = 99;
l = ex->func("Hello"); // crashes here
free(ex);
}
return 0;
}
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314