3 ms·
> move stuff around as void * People do that because they don't understand how to define and use opaque pointers. Also if someone would put the C standards co
by Gibbon1 4y ago
> move stuff around as void *
People do that because they don't understand how to define and use opaque pointers.
Also if someone would put the C standards committee on an ice flow and replace them with people willing to add first class types and tagged unions to C that would be nice.
- gsinclair 4y agoice floe*
- 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; }