In typedef and struct namespaces in C vs C++, one of the comments seems to imply that exposing some struct foo
is preferable to using typedef along the lines of...
typedef struct foo foo;
...and then using foo
instead of struct foo
throughout the API.
Are there any downsides to the latter variant?
On whether or not to typedef structure types:
Here is some opinions around (all against typedefing structures):
From OpenBSD style guide:
"Avoid using typedefs for structure types. This makes it impossible for applications to use pointers to such a structure opaquely, which is both possible and beneficial when using an ordinary struct tag."
From Linux kernel coding style:
"It's a mistake to use typedef for structures and pointers."
From Expert C Programming by Peter Van der Linden:
"Don't bother with typedefs for structs. All they do is save you writing the word "struct", which is a clue that you probably shouldn't be hiding anyway."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With