6 ms·
> People do that because they don't understand how to define and use opaque pointers. what are opaque pointers?
by avinassh 4y ago
> People do that because they don't understand how to define and use opaque pointers.
what are opaque pointers?
- masklinn 4y agoPointers to a well-defined type, but one which does not reveal the underlying datatype so a user is unable to interact with the actual data without going through the library’s exposed API (or at least strongly disincentivised from doing it). IIRC the normal way to do that in C is to use an incomplete type, aka just have a struct foo; In the header file and define the actual struct contents in the implementation file.
- Gibbon1 4y agoYou can create a pointer with a type but no storage definition. // foo_t is opaque typedef struct foo_s foo_t; // function defined taking an opaque pointer int Baz(foo_t *f); // actual definition typedef struct foo_s { int bar; } foo_t; // function def int Baz(foo_t *f) { return f->bar; }