c - Hiding the internals of a structure -


in api, there advantage using type void * handle structures returned user (as opposed using type name_of_the_structure * , hiding implementation)?

if use void* contents black box user can't know about. loose type safety, user of api can pass any pointer function , have no simple way of detecting if it's correct pointer or not.

fortunately, don't have hide structure. have public header distributed api, declares structure, like

struct my_special_struct; 

then functions can still declared using pointers structure, , user too, user have use functions create actual instances, , user can't use structure access internal fields or size using sizeof.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -