Changes: Dropped confusing macro example for side efects and focus on precedence. Added references. diff against in-kernel version attached. Regards Michael --- CodingStyle.mhf.orig.3 2004-02-14 09:29:55.000000000 +0800 +++ CodingStyle 2004-02-15 04:30:40.000000000 +0800 @@ -182,6 +182,7 @@ and it gets confused. You know you're brilliant, but maybe you'd like to understand what you did 2 weeks from now. + Chapter 6: Centralized exiting of functions Albeit deprecated by some people, the equivalent of the goto statement is @@ -387,11 +388,12 @@ 3) macros with arguments that are used as l-values: FOO(x) = y; will bite you if somebody e.g. turns FOO into an inline function. -4) forgetting about side effects: macros defining expressions must enclose each -parameter and the expression in parentheses. +4) forgetting about precedence: macros defining constants using expressions +must enclose the expression in parentheses. Beware of similar issues in +macros using parameters. +#define CONSTANT 0x4000 #define CONSTEXP (CONSTANT | 3) -#define MACWEXP(a,b) ((a) + (b)) Chapter 12: Printing kernel messages @@ -403,3 +405,17 @@ Kernel messages do not have to be terminated with a period. Printing numbers in parenthesis (%d) adds no value and should be avoided. + + + Chapter 13: References + +The C Programming Language, Second Edition +by Brian W. Kernighan and Dennis M. Ritchie. +Prentice Hall, Inc., 1988. +ISBN 0-13-110362-8 (paperback), 0-13-110370-9 (hardback). + +GNU manuals for cpp, gcc and indent, available from www.gnu.org, while in +compliance with K&R and this text. + +-- +This document was updated by a community effort on LKML on 14 February 2004.