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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -