Typedef is very useful for portable names, tag names (typedef struct foo Foo;
) and
keeping complicated (function) declarations readable (typedef int
(*cmpfunc)(const void *, const void *);
).
But are there situations in C where a typedef is really truly needed? Where you cannot accomplish the same by simple writing out the derived type.
To clarify a bit: I mean for language users, not implementers. The whole of stdint.h
is a good example of the second category.
Conclusion
Thanks for all your input. I think I can summarise it as:
- The C99 library needs typedef to implement the various
(u)intN_t
types. - On C89 you really want to use typedefs yourself to create similar portable types.
- You might need typedef when using the
va_arg
macro, but I doubt you will encounter these derivative types in practise.