D
#define
Hello,
Does any body know the advantage of writing function argument as void*
(rather than using int*, char* etc). what is the advantage or
disadvantage of this.
I've seen most of the library functions are implemented this was, as
they provide generic interface.
/*Function defination*/
int Msg_Edit(void *ptr)
{
return *((int*)ptr); //here i should know the type before hand as
int....
}
/* Function call */
Msg_Edit(&msg);
Now msg buffer can be of any type char, int, float....(Am i right)
Is there a way in way in C, by which i know the type of pointer passed
to the function on runtime.
otherwise i'll need to typecast ptr to a specific type (int*, char*
etc) which should be prior knownto me.
Then, what is the main advantage of this approach...
Best Regards,
#define.
Does any body know the advantage of writing function argument as void*
(rather than using int*, char* etc). what is the advantage or
disadvantage of this.
I've seen most of the library functions are implemented this was, as
they provide generic interface.
/*Function defination*/
int Msg_Edit(void *ptr)
{
return *((int*)ptr); //here i should know the type before hand as
int....
}
/* Function call */
Msg_Edit(&msg);
Now msg buffer can be of any type char, int, float....(Am i right)
Is there a way in way in C, by which i know the type of pointer passed
to the function on runtime.
otherwise i'll need to typecast ptr to a specific type (int*, char*
etc) which should be prior knownto me.
Then, what is the main advantage of this approach...
Best Regards,
#define.