c - Issue in passing a structure to a function accepting void * parameter -
i want call function of type foo(void * data) having input parameter struct variable.
i have heard when input format of type void, accepts every type of input variable type. nevertheless, error message.
struct info{ int element; }; struct info inserter_info; inserter_info.element = 0; inserter(inserter_info); where inserter() prototyped void * inserter(void * data).
i tried casting got error messages.
i have heard when input format of type void, accepts every type of input variable type
absolutely wrong !!! void means nothing. accepts nothing.
however, void * considered generic pointer. quote c11 standard document, chapter 6.3.2.3, pointers, paragaraph 1,
a pointer void may converted or pointer object type. pointer object type may converted pointer void , again; result shall compare equal original pointer.
using attribute, many times, function parameter written void * that, function can accept different types of pointer , then, inside function body, based on other paramater, received pointer converted (casted) actual pointer type before using it.
if check properly, parameter function not void, it's void *.
you need call function like
inserter(&inserter_info); p.s - compiler should have warned regarding mismatch.
Comments
Post a Comment