4 ms·
void* is used rarely in practice, apart from perhaps kernel mode or language VM's. I have a 150kloc program in front of me which doesn't have a single void*.
by harrytuttle 13y ago
void* is used rarely in practice, apart from perhaps kernel mode or language VM's. I have a 150kloc program in front of me which doesn't have a single void*.
- michaelwww 13y agoGreat. That makes more sense. I must have misunderstood what you were saying.
- harrytuttle 13y agoYes we're not gluttons for punishment believe me :)
- nly 13y agovoid* is used in practically every C library that offers a callback facility.
- harrytuttle 13y agoAlmost... You have a typed pointer to a function but that's not a void pointer and the "New C Standard" 6.3.2.3 states that you can't cast a function pointer to a void*.
- ygra 13y agoNot for function pointers; for passing data to callbacks that can be any type.
- harrytuttle 13y agoCan you provide an example? Not 100% sure in which context you are talking about.
- ygra 13y agoAs an example, SQLite: int sqlite3_exec( sqlite3*, /* An open database */ const char *sql, /* SQL to be evaluated */ int (*callback)(void*,int,char**,char**), /* Callback function */ void *, /* 1st argument to callback */ char **errmsg /* Error msg written here */ ); Here the void * is an argument that is passed in the callback as well so that you can update your own struct with the result, for example. Singe the library cannot know anything about your types, void * is the only option.
- harrytuttle 13y agoThanks for the example. Agree entirely then :)