Do you need to malloc space for function pointers in a struct in C? -



Do you need to malloc space for function pointers in a struct in C? -

for example, have create struct in function parameters: function pointer format: void (*func)(void *) , int id.

the struct create following:

typedef struct illustration { int id; void (*func)(void *); } example;

now question when malloc space whole struct, malloc space void function pointer because pointer? if so, how, since can't size of void pointer? thanks.

when malloc space struct, sizeof(your_struct) gets size of entire struct. don't need individually allocate space each element. after mallocing, can set function pointer other field of struct.

c pointers struct malloc dynamic-memory-allocation

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -