Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 44891
b: refs/heads/master
c: 58637ec
h: refs/heads/master
i:
  44889: cc0de9c
  44887: 1eaedf6
v: v3
  • Loading branch information
Robert P. J. Day authored and Linus Torvalds committed Dec 22, 2006
1 parent f7b4983 commit 624ab1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 163ca88b9c5858909ee3f8801ae0096b5f94e835
refs/heads/master: 58637ec90b7ceed5909e726ac90118852f79d2b1
18 changes: 18 additions & 0 deletions trunk/Documentation/CodingStyle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 624ab1a

Please sign in to comment.