Re: typedefs and structs [was Re: [PATCH 16/42]: PCI: PCI Error reporting callbacks]

From: linas
Date: Mon Nov 07 2005 - 15:41:33 EST


On Mon, Nov 07, 2005 at 12:02:57PM -0800, Greg KH was heard to remark:
> On Mon, Nov 07, 2005 at 01:36:00PM -0600, linas wrote:
> > On Mon, Nov 07, 2005 at 11:02:45AM -0800, Greg KH was heard to remark:
> > >
> > > No, never typedef a struct. That's just wrong.
> >
> > Its a defacto convention for most C-language apps, see, for
> > example Xlib, gtk and gnome.
>
> The kernel is not those projects.

!!

> > Also, "grep typedef include/linux/*" shows that many kernel device
> > drivers use this convention.
>
> They are wrong and should be fixed.

What, precisely, is wrong?

> See my old OLS paper on all about the problems of using typedefs in
> kernel code.

Is this on the web somewhere? Google is having trouble finding it.

I understand that old code bases often choke on typedefs;
forward declarations are a big problem. Not to be rude,
but choking for forward decl's is often a symptom of
poorly-designed code.

> > > gcc should warn you
> > > just the same if you pass the wrong struct pointer
> >
> > There were many cases where it did not warn (I don't remember
> > the case of subr calls). I beleive this had to do with ANSI-C spec
> > issues dating to the 1990's; traditional C is weakly typed.
> >
> > Its not just gcc; anyoe who coded for a while eventually discovered
> > that tyedefs where strongly typed, but "struct blah *" were not.
>
> Sorry, but you are using a broken compiler if it doesn't complain about
> this.

Uhh, gcc?

Maybe I've just got more mileage under my wheels. Of all of the
compilers I've used, gcc has always had the strictest checking,
and was the most verbose about warnings. There's a trick that pros
use when they inherit crufty old code: run it through gcc first, and
clean it up, even if the project requires using some other compiler.

I was simply stating a fact about gcc and about standard ANSI-C
type-checking that is "well known" to anyone who's been around the
block. I was not trying to start an argument.

--linas

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/