3 ms·
struct public_stuff { ... } struct private_stuff { struct public_stuff public; ... } struct public_stuff *make_public(
by dfawcus 3y ago
struct public_stuff {
...
}
struct private_stuff {
struct public_stuff public;
...
}
struct public_stuff *make_public(/* ... */) {
struct private *prv = malloc(sizeof *prv);
/* ... */
return &prv->public;
}
Then when passed in to functions, cast the passed in struct pointer to the private one.
The public struct doesn't even have to be at the start if one make appropriate use of offsetof and ensuring valid alignment.
Nothing new under the sun...