typedefs and structs [was Re: [PATCH 16/42]: PCI: PCI Error reporting callbacks]
Greg KH
greg at kroah.com
Tue Nov 8 07:02:57 EST 2005
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:
> >
> > > I'm not to clear on what "sparse" can do; however, in the good old days,
> > > gcc allowed you to commit great sins when passing "struct blah *" to
> > > subroutines, whereas it stoped you cold if you tried the same trick
> > > with a typedef'ed "blah_t *". This got me into the habit of turning
> > > all structs into typedefs in my personal projects. Can we expect
> > > something similar for the kernel, and in particular, should we start
> > > typedefing structs now?
> >
> > 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.
See my old OLS paper on all about the problems of using typedefs in
kernel 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.
thanks,
greg k-h
More information about the Linuxppc64-dev
mailing list