4 ms·
> Now you have a named struct bla_t which is typedef’ed to a type alias bla_t, and the named struct can be properly forward-declared. The article doesn't menti
by hgs3 4y ago
> Now you have a named struct bla_t which is typedef’ed to a type alias bla_t, and the named struct can be properly forward-declared.
The article doesn't mention it, but C11 allows typedef redefinitions which means instead of forward declaring "struct bla_t" and referring to it with the struct keyword, you can instead forward declare it as "typedef struct bla_t bla_t" and refer to it _without_ the struct keyword.
See N1360 [1] for details.
[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1360.htm https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1360.htm
- Gibbon1 4y agoReminds me I found something, perhaps it's yet another gcc thing but. You can define an opaque pointer in a header file thing_pubic.h typedef struct foo_s foo_t; // foo_t is opaque. And the actual def in a header file thing_private.h typedef struct foo_s { int foo; } foo_t; // def of foo_t If you include the first header file you get foo_t as an opaque type. If you include the second or _both_ headers you get the full type.