All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: "Kevin D. Kissell" <kevink@paralogos.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
	Chad Reese <kreese@caviumnetworks.com>,
	linux-mips@linux-mips.org
Subject: Re: Is there no way to shared code with Linux and other OSes?
Date: Sat, 22 Nov 2008 15:35:42 +0000	[thread overview]
Message-ID: <20081122153542.GB31703@linux-mips.org> (raw)
In-Reply-To: <4927E2A4.5000702@paralogos.com>

On Sat, Nov 22, 2008 at 04:44:52AM -0600, Kevin D. Kissell wrote:

>>   
>>> [This should be good for some useless weekend flaming.]
>>>     
>>
>> Yeah! ;-)

With the oil price down so far we gotta make some good use of that ;-)

> That's a better argument than the one in the HTML version of  
> Documentation/CodingStyle.txt that I had bookmarked (which was what I  
> cited).  Interestingly, if I look at the *current* Linux  
> Documentation/CodingStyle.txt for 2.6.28-rc6, the blanket interdiction  
> of typedefs is no longer there!  Things *have* evolved, as I said they'd  
> have to, to recognize 5 (a good Illuminati number) cases where typedefs  
> are permitted.  Superficially, based on Chad's description (I admit that  
> I haven't been reviewing his patches) the Cavium case would seem to fall  
> into the first category. Is the MIPS Linux community now some kind of  
> ultra-orthodox sub-sect of the Linux cult? ;o)

There was never a blanket interdiction of typedefs though it may seem to
and unfortunately scripts/checkpatch.pl also bitches about every typedef,
no matter what.  It was rather a restriction to only using typedefs for
simple types such as char, int or pointers but not on structs - otherwise
the definitions for u32 etc. would not have made it in.  In a 2002 OLS
paper giving a bit of a rationale for the Linux coding standard Greg KH
writes:

[...]
typedef is evil

typedef should not be used in naming any of your structures. Almost all main
kernel structures do not have a typedef to shorten their usage. This
includes the following:

	struct inode
	struct dentry
	struct file
	struct buffer_head
	struct user
	struct task_struct

Using typedef tries to hide the real type of a variable. There have been
records of some kernel code using typedefs nested up to 4 layers deep,
preventing the programmer from telling what type of variable they are really
using. This can easily cause very large structures to be accidentally
declared on the stack, or to be returned from functions if the programmer
does not realize the size of the structure.  typedef can also be used as a
crutch to keep from typing long structure denitions. If this is the case,
the structure names should be made shorter, according to the above listed
naming rules.  Never define a typedef to just signify a pointer to a
structure, as in the following example:

	typedef struct foo
	{
		int bar;
		int baz;
	} foo t, *pfoo_t;

This again hides the true type of the variable, and is using the name of
the variable type to define what is is (see the comment about Hungarian
notation previously.

Some examples of where typedef is badly used are in the include/raid/md*.h
files where every structure has a typedef assigned to it, and in the
drivers/acpi/include/*.h files, where a lot of the structures do not even
have a name assigned to them, only a typedef.

The only place that using typedef is acceptable, is in declaring function
prototypes. These can be difcult to type out every time, so declaring a
typedef for these is nice to do. An example of this is the bh_end_io_t
typedef which is used as a parameter in the init buffer() call. This is
defined in include/fs.h as:

	typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);

[...]

The full paper is available at http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_paper/codingstyle.ps

  Ralf

  reply	other threads:[~2008-11-22 15:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-22  8:31 Is there no way to shared code with Linux and other OSes? Chad Reese
2008-11-22  9:54 ` Kevin D. Kissell
2008-11-22 10:13   ` Geert Uytterhoeven
2008-11-22 10:44     ` Kevin D. Kissell
2008-11-22 15:35       ` Ralf Baechle [this message]
2008-11-22 19:08         ` Chad Reese
2008-11-24 13:14           ` Ralf Baechle
2008-11-24 17:52             ` Chad Reese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081122153542.GB31703@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=geert@linux-m68k.org \
    --cc=kevink@paralogos.com \
    --cc=kreese@caviumnetworks.com \
    --cc=linux-mips@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.