What do *YOU* think of typedefs?

greg at sdcsvax.UUCP greg at sdcsvax.UUCP
Sat Mar 3 05:34:27 AEST 1984


In general, typedefs should be avoided.  There are only a couple of
cases where typedefs make sense -- primairly to improve transparency or
to provide portability.  Another way of saying the same thing is that
if you ever make use of the fields of a typedef, then you should NOT be
using typedefs.  Only if you always use the object as a primitive are
typedefs proper.

Typedefs are one way that C begins to lean toward more modern forms of
structuring, like information hiding.  But like many of the tools
provided by C, it must be used with care and discipline.  Typedefs draw
a very thin veil over the actual definition of the object.  It is thin
enough so that you can see through it if you really need to. The
fact that it is there means that you shouldn't need to, unless you are
the one that implemented the type (in which case, the functionality
should be provided by subroutines or macros with the actual mechanism
hidden).

Now, don't get me wrong -- typedefs are fun and useful.  But the
overuse of typedefs can confuse rather than make clearer.



More information about the Comp.lang.c mailing list