Typedef is very useful for portable names, tag names (typedef struct foo Foo;
) and
keeping complicated (function) declarations readable (typedef int
(*cmpfunc
Yes. Integer types that have to be a fixed size. e.g. int32_t
(and you want your code to have a fighting chance of being portable).
No. I think I'm safe in saying that!
Thanks all for your answers. I looked some more myself and found this in C99, J.2 Undefined behaviour:
The behavior is undefined in the following circumstances: [...]
- The type parameter to the
va_arg
macro is not such that a pointer to an object of that type can be obtained simply by postfixing a*
(7.15.1.1).
So when you want to pass/extract complicated derived types to va_arg
such as int (*)[]
you need to typedef
this type to something for which this is possible (updated/corrected):
typedef int (*intarrptr)[4];
intarrptr x = va_arg(ap, intarrptr);
Since it is difficult to find and actual useful case for this one might conclude that it is not a strong argument for the necessity of typedef
.