tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys/arch/powerpc/oea



On Mon, Nov 15, 2010 at 03:47:32PM -0500, der Mouse wrote:
 > > [...] just forward declarations of the structs.
 > 
 > > (this is, btw, one of the reasons to avoid silly typedefs)
 > 
 > I'm not sure what typedefs have to do with it.  typedeffing a name to
 > an incomplete ("forward") struct type works just fine:
 > 
 > struct foo;
 > typedef struct foo FOO;
 > 
 > (You can't do anything with a FOO without completing the struct type,
 > but you can work with pointers to them....)

But now there's no protection against divergence; that is, if I have

   typedef struct foo FOO;

in one header and a typo'd

   typedef struct tfoo FOO;

in another, assuming suitable ifdef guards as already mentioned, now
FOO can be two different things, and the inconsistency in the
cut-and-pasted-material might not be detected for some time.

However, if I just have

   struct foo;

in multiple headers there aren't very many ways this can be wrong that
will compile at all. The only common way for this to go bad is if
you've removed struct foo from your program completely; then you have
to hunt down all the forward declarations by hand and kill them off.
But that's more or less unavoidable.

The difference between these two cases is inherent in the fact that
the typedef form is declaring two things and the plain struct
declaration is declaring only one... there's no particular reason C
couldn't provide a way to create a forward declaration (without
definition) of a typedef name, but it doesn't.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index