When should use use _t
? Never? It's reserved by a major standard (POSIX) and even if it's not now, your code might someday be used in a POSIX environment, so using _t
is a bad idea.
I would go further to say that over-use of typedef
is bad in general. If your type is a struct
, union
, or enum
, use these keywords when you declare variables and it makes your code more clear. Use of typedef
is best reserved for when you want to make the underlying type invisible for abstraction/encapsulation purposes. A few great examples from standard C are size_t
, int32_t
, mbstate_t
, and the stdio FILE
.
Some of the worst abuses of typedef
are by the Windows API (WORD
, DWORD
, INT
, LPSTR
etc.) and glib (gint
, gchar
, etc.). Making duplicates of the standard C types with the same intended usage is only confusing and serves to lock developers into your library/platform by polluting all the code with these nonstandard type names.
_t
are reserved by some standard (not sure which). Though whatever you do, don't do_type_t
. Pick_type
or_t
(or something else), but please don't stack them. That's just silly. – Roving_t
are reserved in POSIX: opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html. Not that I pay much attention to that (I typedef to names ending in_t
pretty often). – Translocation_t
for types defined in ANY header. – Bollworm