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

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

 



On Mon, Nov 07, 2005 at 12:56:21PM -0600, linas wrote:
> On Mon, Nov 07, 2005 at 10:27:27AM -0800, Greg KH was heard to remark:
> > 
> > 3) realy strong typing that sparse can detect.
> 
> Am compiling now.
> 
> > enums don't really work, as you can get away with using an integer and
> > the compiler will never complain.  Please use a typedef (yeah, I said
> > typedef) in the way that sparse will catch any bad users of the code.
> 
> How about typedef'ing  structs?

No.  Use __bitwise.  See the lkml archives for how to do this properly.

> 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.  gcc should warn you
just the same if you pass the wrong struct pointer (and all of your code
builds without warnings, right?)

> (Documentation/CodingStyle doesn't mention typedef at all).

If it does, it should say not to use it at all :)

Except for this case, it's special...

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux