c - Error on dynamically allocating memory to function pointer array -
int kpsize = 4; int kpidx = 0; typedef int (*eventhandler) (void *); eventhandler *keyfuncarray = (eventhandler *) malloc(sizeof(eventhandler) * kpsize);
i following error on compiling, error c2099: initializer not constant on following line
eventhandler *keyfuncarray = (eventhandler *) malloc(sizeof(eventhandler) * kpsize);
you cannot init malloc
global variable.
you must write, eg:
eventhandler *keyfuncarray; int main () { keyfuncarray = malloc(sizeof(eventhandler) * kpsize) // stuff:.. return 0; }
take to: do cast malloc return?
Comments
Post a Comment