mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Randy Dunlap <randy.dunlap@oracle.com>
To: "Robert P. J. Day" <rpjday@mindspring.com>
Cc: Linux kernel mailing list <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH] Add a new section to CodingStyle, promoting include/linux/kernel.h.
Date: Mon, 18 Dec 2006 09:57:04 -0800	[thread overview]
Message-ID: <20061218095704.59687cc9.randy.dunlap@oracle.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0612181238210.27907@localhost.localdomain>

On Mon, 18 Dec 2006 12:43:35 -0500 (EST) Robert P. J. Day wrote:

> 
>   Add a new section to the CodingStyle file, encouraging people not to
> re-invent available kernel macros such as ARRAY_SIZE(),
> FIELD_SIZEOF(), min() and max(), among others.
> 
> Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>

Acked-by: Randy Dunlap <randy.dunlap@oracle.com>


> ---
> 
>   NOTE:  at the moment, there is not a single invocation of the
> FIELD_SIZEOF() macro anywhere in the entire source tree, so if someone
> had a hankering to rename it to something more catchy, now would be a
> good time and i can always resubmit the patch i sent in yesterday.
> 
> 
> 
> diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
> index 0ad6dcb..a736333 100644
> --- a/Documentation/CodingStyle
> +++ b/Documentation/CodingStyle
> @@ -682,6 +682,24 @@ result.  Typical examples would be functions that return pointers; they use
>  NULL or the ERR_PTR mechanism to report failure.
> 
> 
> +		Chapter 17:  Don't re-invent the kernel macros
> +
> +The header file include/linux/kernel.h contains a number of macros that
> +you should use, rather than explicitly coding some variant of them yourself.
> +For example, if you need to calculate the length of an array, take advantage
> +of the macro
> +
> +  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
> +
> +Similarly, if you need to calculate the size of some structure member, use
> +
> +  #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> +
> +There are also min() and max() macros that do strict type checking if you
> +need them.  Feel free to peruse that header file to see what else is already
> +defined that you shouldn't reproduce in your code.
> +
> +
> 
>  		Appendix I: References

---
~Randy

  reply	other threads:[~2006-12-18 17:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-18 17:43 Robert P. J. Day
2006-12-18 17:57 ` Randy Dunlap [this message]
2006-12-18 20:18 ` Jan Engelhardt
2006-12-18 21:50 ` Erik Mouw
2006-12-18 21:54   ` Robert P. J. Day

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=20061218095704.59687cc9.randy.dunlap@oracle.com \
    --to=randy.dunlap@oracle.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpjday@mindspring.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®