Skip to contentSkip to conversation

CodingStyle updates

PATCH/RFC Randy Dunlap 9 participants 20 messages Dec 7, 2006 – Dec 15, 2006 Documentation

lore
Share & tools
lore
#0 lore raw

From: Randy Dunlap <[email protected]>

Add some kernel coding style comments, mostly pulled from emails by Andrew Morton, Jesper Juhl, and Randy Dunlap.

- add paragraph on switch/case indentation
- add paragraph on multiple-assignments
- add more on Braces
- add section on Spaces
- add paragraph on function breaks in source files
- add paragraph on EXPORT_SYMBOL placement
- add section on /*-comment style, long-comment style, and data declarations and comments
- correct some chapter number references that were missed when chapters were renumbered

---
 Documentation/CodingStyle |  107 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 102 insertions(+), 5 deletions(-)
Documentation/CodingStyle +102 -5
@@ -35,12 +35,34 @@ In short, 8-char indents make things eas
 benefit of warning you when you're nesting your functions too deep.
 Heed that warning.
 
+The preferred way to ease multiple indentation levels in a switch
+statement is to align the "switch" and its subordinate "case" labels in
+the same column instead of "double-indenting" the "case" labels.  E.g.:
+
+	switch (suffix) {
+	case 'G':
+	case 'g':
+		mem <<= 10;
+	case 'M':
+	case 'm':
+		mem << 10;
+	case 'K':
+	case 'k':
+		mem << 10;
+	default:
+		break;
+	}
+
+
 Don't put multiple statements on a single line unless you have
 something to hide:
 
 	if (condition) do_this;
 	  do_something_everytime;
 
+Don't put multiple assignments on a single line either.  Kernel
+coding style is super simple.  Avoid tricky expressions.
+
 Outside of comments, documentation and except in Kconfig, spaces are never
 used for indentation, and the above example is deliberately broken.
 
@@ -69,7 +91,7 @@ void fun(int a, int b, int c)
 		next_statement;
 }
 
-		Chapter 3: Placing Braces
+		Chapter 3: Placing Braces and Spaces
 
 The other issue that always comes up in C styling is the placement of
 braces.  Unlike the indent size, there are few technical reasons to
@@ -81,6 +103,20 @@ brace last on the line, and put the clos
 		we do y
 	}
 
+This applies to all non-function statement blocks (if, switch, for,
+while, do).  E.g.:
+
+	switch (action) {
+	case KOBJ_ADD:
+		return "add";
+	case KOBJ_REMOVE:
+		return "remove";
+	case KOBJ_CHANGE:
+		return "change";
+	default:
+		return NULL;
+	}
+
 However, there is one special case, namely functions: they have the
 opening brace at the beginning of the next line, thus:
 
@@ -121,6 +157,40 @@ supply of new-lines on your screen is no
 25-line terminal screens here), you have more empty lines to put
 comments on.
 
+		3.1:  Spaces
+
+Linux kernel style for use of spaces depends (mostly) on
+function-versus-keyword usage.  Use a space after (most) keywords.
+The notable exception is "sizeof", which looks like a function
+(and is usually used with parentheses in Linux, although they are
+not required in the language, as in: "sizeof struct file").
+So use a space after these keywords:
+	if, switch, case, for, do, while
+but not with "sizeof".  E.g.,
+	s = sizeof(struct file);
+
+Do not add spaces around (inside) parenthesized expressions.
+This example is *bad*:
+
+	s = sizeof( struct file );
+
+When declaring pointer data or a function that returns a pointer type,
+the preferred use of '*' is adjacent to the data name or function name
+and not adjacent to the type name.  Examples:
+
+	char *linux_banner;
+	unsigned long long memparse(char *ptr, char **retptr);
+	char *match_strdup(substring_t *s);
+
+Use one space around (on each side of) most binary operators, such as
+any of these:
+		=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=
+
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined
+
+and no space around the '.' unary operator.
+
 
 		Chapter 4: Naming
 
@@ -152,7 +222,7 @@ variable that is used to hold a temporar
 
 If you are afraid to mix up your local variable names, you have another
 problem, which is called the function-growth-hormone-imbalance syndrome.
-See next chapter.
+See chapter 6 (Functions).
 
 
 		Chapter 5: Typedefs
@@ -258,6 +328,16 @@ generally easily keep track of about 7 d
 and it gets confused.  You know you're brilliant, but maybe you'd like
 to understand what you did 2 weeks from now.
 
+In source files, separate functions with one blank line.
+If the function is exported, the EXPORT* macro for it should follow
+immediately after the closing function brace line.  E.g.:
+
+int system_is_up(void)
+{
+	return system_state == SYSTEM_RUNNING;
+}
+EXPORT_SYMBOL(system_is_up);
+
 
 		Chapter 7: Centralized exiting of functions
 
@@ -306,16 +386,33 @@ time to explain badly written code.
 Generally, you want your comments to tell WHAT your code does, not HOW.
 Also, try to avoid putting comments inside a function body: if the
 function is so complex that you need to separately comment parts of it,
-you should probably go back to chapter 5 for a while.  You can make
+you should probably go back to chapter 6 for a while.  You can make
 small comments to note or warn about something particularly clever (or
 ugly), but try to avoid excess.  Instead, put the comments at the head
 of the function, telling people what it does, and possibly WHY it does
 it.
 
-When commenting the kernel API functions, please use the kerneldoc format.
+When commenting the kernel API functions, please use the kernel-doc format.
 See the files Documentation/kernel-doc-nano-HOWTO.txt and scripts/kernel-doc
 for details.
 
+Linux style for comments is the pre-C99 "/* ... */" style.
+Don't use C99-style "// ..." comments.
+
+The preferred style for long (multi-line) comments is:
+
+	/*
+	 * This is the preferred style for multi-line
+	 * comments in the Linux kernel source code.
+	 * Please use it consistently.
+	 */
+
+It's also important to comment data, whether they are basic types or
+derived types.  To this end, use just one data declaration per line
+(no commas for multiple data declarations).  This leaves you room for
+a small comment on each item, explaining its use.
+
+
 		Chapter 9: You've made a mess of it
 
 That's OK, we all do.  You've probably been told by your long-time Unix
@@ -591,4 +688,4 @@ Kernel CodingStyle, by [email protected] at
 http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
 
 --
-Last updated on 30 April 2006.
+Last updated on 2006-December-06.

---

Acked-by
#1 lore raw
Quoted 16 lines · Randy Dunlap

From: Randy Dunlap <[email protected]>

Add some kernel coding style comments, mostly pulled from emails by Andrew Morton, Jesper Juhl, and Randy Dunlap.

- add paragraph on switch/case indentation
- add paragraph on multiple-assignments
- add more on Braces
- add section on Spaces
- add paragraph on function breaks in source files
- add paragraph on EXPORT_SYMBOL placement
- add section on /*-comment style, long-comment style, and data declarations and comments
- correct some chapter number references that were missed when chapters were renumbered

Quoted 1 line
Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#2 lore raw
In reply to Randy Dunlap

Documentation/CodingStyle In short, 8-char indents make things eas · line 48

Quoted 11 lines · Randy Dunlap
Documentation/CodingStyle +11 -0
+The preferred way to ease multiple indentation levels in a switch
+statement is to align the "switch" and its subordinate "case" labels in
+the same column instead of "double-indenting" the "case" labels.  E.g.:
+
+	switch (suffix) {
+	case 'G':
+	case 'g':
+		mem <<= 10;
+	case 'M':
+	case 'm':
+		mem << 10;
                ^^^^^^^^^^

Statement has no effect ;-)

Documentation/CodingStyle In short, 8-char indents make things eas · line 51

Quoted 3 lines
Documentation/CodingStyle +3 -0
+	case 'K':
+	case 'k':
+		mem << 10;

Make that <<=.

Documentation/CodingStyle supply of new-lines on your screen is no · line 187

Quoted 3 lines
Documentation/CodingStyle +3 -0
+Use one space around (on each side of) most binary operators, such as
+any of these:
+		=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=

And the ternary operator ?:

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

And no space before these unary operators,
++ (postincrement) -- (postdecrement)

What keyword is "defined"? Did you have too much Perl coffee? :)

Quoted 1 line

+and no space around the '.' unary operator.

Same goes for ->

Quoted 1 line

+Linux style for comments is the pre-C99 "/* ... */" style.

Aka C89.

Documentation/CodingStyle time to explain badly written code. · line 408

Quoted 9 lines
Documentation/CodingStyle +9 -0
+Don't use C99-style "// ..." comments.
+
+The preferred style for long (multi-line) comments is:
+
+	/*
+	 * This is the preferred style for multi-line
+	 * comments in the Linux kernel source code.
+	 * Please use it consistently.
+	 */

Description: Stars to the left with two almost blank (/*, */) lines.

	-`J'
#3 lore raw
Quoted 1 line · Jan Engelhardt

What keyword is "defined"? Did you have too much Perl coffee? :)

Maybe macro formatting?

#if defined(CONFIG_FOO)

Chris

#4 lore raw
Quoted 6 lines
Quoted 2 lines

What keyword is "defined"? Did you have too much Perl coffee? :)

Maybe macro formatting?

#if defined(CONFIG_FOO)

Ah thanks for the hint. This also raises another stylistic aspect:

#ifdef XYZ over #if defined(XYZ) when there is only one macro to be tested for.

	-`J'
#5 lore raw
Quoted 4 lines · Jan Engelhardt
Quoted 4 lines
Quoted 1 line

What keyword is "defined"? Did you have too much Perl coffee? :)

Maybe macro formatting?

#if defined(CONFIG_FOO)

Yes, that's it.

Quoted 3 lines

Ah thanks for the hint. This also raises another stylistic aspect:

#ifdef XYZ over #if defined(XYZ) when there is only one macro to be tested for.

I'm not sure that we care enough to put it into CodingStyle.

Signature · 1 line
~Randy
#6 lore raw
In reply to Jan Engelhardt
Quoted 14 lines · Jan Engelhardt

Documentation/CodingStyle In short, 8-char indents make things eas · line 48

Quoted 11 lines · Randy Dunlap
Documentation/CodingStyle +11 -0
+The preferred way to ease multiple indentation levels in a switch
+statement is to align the "switch" and its subordinate "case" labels in
+the same column instead of "double-indenting" the "case" labels.  E.g.:
+
+	switch (suffix) {
+	case 'G':
+	case 'g':
+		mem <<= 10;
+	case 'M':
+	case 'm':
+		mem << 10;
                ^^^^^^^^^^
Quoted 1 line

Statement has no effect ;-)

Argh, thanks, fixed these.
And removed most fall-throughs to make it a better example.

Quoted 5 lines

Documentation/CodingStyle supply of new-lines on your screen is no · line 187

Quoted 3 lines
Documentation/CodingStyle +3 -0
+Use one space around (on each side of) most binary operators, such as
+any of these:
+		=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=

And the ternary operator ?:

Added.

Quoted 11 lines

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

And no space before these unary operators,
++ (postincrement) -- (postdecrement)

What keyword is "defined"? Did you have too much Perl coffee? :)

Quoted 1 line

+and no space around the '.' unary operator.

Same goes for ->

Added.

Quoted 3 lines
Quoted 1 line

+Linux style for comments is the pre-C99 "/* ... */" style.

Aka C89.

Changed.

Quoted 11 lines

Documentation/CodingStyle time to explain badly written code. · line 408

Quoted 9 lines
Documentation/CodingStyle +9 -0
+Don't use C99-style "// ..." comments.
+
+The preferred style for long (multi-line) comments is:
+
+	/*
+	 * This is the preferred style for multi-line
+	 * comments in the Linux kernel source code.
+	 * Please use it consistently.
+	 */

Description: Stars to the left with two almost blank (/*, */) lines.

Added.

Thanks. Will resend later today...

Signature · 1 line
~Randy
#7 lore raw
In reply to Randy Dunlap

Hi Randy,

On Thursday 07 December 2006 08:48, Randy Dunlap wrote:
[snip]

Quoted 21 lines
Documentation/CodingStyle +21 -0
+		3.1:  Spaces
+
+Linux kernel style for use of spaces depends (mostly) on
+function-versus-keyword usage.  Use a space after (most) keywords.
+The notable exception is "sizeof", which looks like a function
+(and is usually used with parentheses in Linux, although they are
+not required in the language, as in: "sizeof struct file").
+So use a space after these keywords:
+	if, switch, case, for, do, while
+but not with "sizeof".  E.g.,
+	s = sizeof(struct file);
+
+Do not add spaces around (inside) parenthesized expressions.
+This example is *bad*:
+
+	s = sizeof( struct file );
+
+When declaring pointer data or a function that returns a pointer type,
+the preferred use of '*' is adjacent to the data name or function name
+and not adjacent to the type name.  Examples:
+

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 10 lines
Documentation/CodingStyle +10 -0
+	char *linux_banner;
+	unsigned long long memparse(char *ptr, char **retptr);
+	char *match_strdup(substring_t *s);
+
+Use one space around (on each side of) most binary operators, such as
+any of these:
+		=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=
+
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

You could mention typeof too, which is a keyword but should be done like sizeof.

Signature · 5 lines
Cheers,
Alistair.

Final year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.
#8 lore raw
Quoted 4 lines · Alistair John Strachan

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

You could mention typeof too, which is a keyword but should be done like sizeof.

Hm, is that a gcc-ism? It's not listed in the C99 spec.

Are there other gcc-isms that I should add?

Thanks.

Signature · 1 line
~Randy
#9 lore raw

From: Randy Dunlap <[email protected]>
Date: Thu, 07 Dec 2006 15:00:31 -0800

Quoted 11 lines
Quoted 5 lines · Alistair John Strachan

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

You could mention typeof too, which is a keyword but should be done like sizeof.

Hm, is that a gcc-ism? It's not listed in the C99 spec.

Are there other gcc-isms that I should add?

Perhaps you should add typeof and alignof, for starters.

#10 lore raw
Quoted 11 lines · On Thu, 07 Dec 2006 15:06:35 -0800 (PST) David Miller wrote:

From: Randy Dunlap <[email protected]>
Date: Thu, 07 Dec 2006 15:00:31 -0800

Quoted 8 lines
Quoted 5 lines · Alistair John Strachan

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

You could mention typeof too, which is a keyword but should be done like sizeof.

Quoted 5 lines
Quoted 3 lines

Hm, is that a gcc-ism? It's not listed in the C99 spec.

Are there other gcc-isms that I should add?

Perhaps you should add typeof and alignof, for starters.

OK, I added both of those. Thanks.

Will resend soon.
---
~Randy

#11 lore raw
In reply to Randy Dunlap
Quoted 10 lines · Randy Dunlap
Quoted 6 lines

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 3 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

You could mention typeof too, which is a keyword but should be done like sizeof.

Hm, is that a gcc-ism? It's not listed in the C99 spec.

Are there other gcc-isms that I should add?

__attribute__(()) perhaps, which is often seen in kernel code.

-fno-gnu-keywords
Do not recognize "typeof" as a keyword, so that code can use this word as an identifier. You can use the keyword "__typeof__" instead. -ansi implies -fno-gnu-keywords.

Ergo it's a GNUism/GCCism. As long as <whatever> is used in kernel code, it should be documented.

	-`J'
#12 lore raw
In reply to Randy Dunlap

On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:

[snip]

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

Uhm, that doesn't compute... If you don't put a space after sizeof, the program won't compile.

int c;
printf("%d", sizeofc);

Options are:

sizeof c
sizeof(c)

or

sizeof (c)

If you take sizeof the type rather than the variable, the options are

sizeof(int)

or

sizeof (int)

[snip]

Regards: David Weinehall

Signature · 3 lines
 /) David Weinehall <[email protected]> /) Northern lights wander      (\
//  Maintainer of the v2.0 kernel   //  Dance across the winter sky //
\)  http://www.acc.umu.se/~tao/    (/   Full colour fire           (/
#13 lore raw
Quoted 4 lines · David Weinehall

On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:

[snip]

Quoted 8 lines

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

Uhm, that doesn't compute... If you don't put a space after sizeof, the program won't compile.

int c;
printf("%d", sizeofc);

Uh, we prefer not to see "sizeof c". IOW, we prefer to have the parentheses use all the time. Maybe I need to say that better?

Quoted 21 lines

Options are:

sizeof c
sizeof(c)

or

sizeof (c)

If you take sizeof the type rather than the variable, the options are

sizeof(int)

or

sizeof (int)

[snip]

Regards: David Weinehall

Signature · 1 line
~Randy
#14 lore raw
Quoted 11 lines · Randy Dunlap
Quoted 10 lines · David Weinehall

On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:

[snip]

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

Uhm, that doesn't compute... If you don't put a space after sizeof, the program won't compile.

Quoted 5 lines
Quoted 2 lines

int c;
printf("%d", sizeofc);

Uh, we prefer not to see "sizeof c". IOW, we prefer to have the parentheses use all the time. Maybe I need to say that better?

here's a *really* rough first pass, i'm sure the end result would need some hand tweaking:

=============================================
#!/bin/sh

DIR=$1

#
# Put in missing parentheses.
#

for f in $(grep -Erl "sizeof [^\(]" ${DIR}) ; do
echo $f
perl -pi -e "s/sizeof ([*]?[A-Za-z0-9_>\[\]\.-]+)( *)/sizeof\(\1\)\2/g" $f
done

#
# Delete possible space between "sizeof" and "(". #

for f in $(grep -rl "sizeof (" ${DIR}) ; do
perl -pi -e "s/sizeof \(/sizeof\(/g" $f
done

#
# Delete obnoxious spaces inside parentheses.
#

for f in $(grep -rl "sizeof( " ${DIR}) ; do
perl -pi -e "s/sizeof\( *([^ \)]+) *\)/sizeof\(\1\)/g" $f
done
===========================================

rday

#15 lore raw
Quoted 13 lines · On Thu, 14 Dec 2006 19:07:27 -0500 (EST) Robert P. J. Day wrote:
Quoted 11 lines · Randy Dunlap
Quoted 10 lines · David Weinehall

On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:

[snip]

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

Uhm, that doesn't compute... If you don't put a space after sizeof, the program won't compile.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

int c;
printf("%d", sizeofc);

Uh, we prefer not to see "sizeof c". IOW, we prefer to have the parentheses use all the time. Maybe I need to say that better?

here's a *really* rough first pass, i'm sure the end result would need some hand tweaking:

You can certainly send such (generated) patches to Andrew or other subsystem maintainers if you'd like, but I'm more interested in not adding more crud to the tree in the future.

IOW, sure, we prefer sizeof(foo) to sizeof foo, but the latter isn't killing us. If someone is there making other changes, it would be OK to change that also.

Compare: http://lkml.org/lkml/2006/12/7/191

---
~Randy

#16 lore raw
Quoted 24 lines · Randy Dunlap
Quoted 13 lines · On Thu, 14 Dec 2006 19:07:27 -0500 (EST) Robert P. J. Day wrote:
Quoted 11 lines · Randy Dunlap
Quoted 10 lines · David Weinehall

On Thu, Dec 07, 2006 at 12:48:38AM -0800, Randy Dunlap wrote:

[snip]

Documentation/CodingStyle supply of new-lines on your screen is no · line 190

Quoted 2 lines
Documentation/CodingStyle +2 -0
+but no space after unary operators:
+		sizeof  ++  --  &  *  +  -  ~  !  defined

Uhm, that doesn't compute... If you don't put a space after sizeof, the program won't compile.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

int c;
printf("%d", sizeofc);

Uh, we prefer not to see "sizeof c". IOW, we prefer to have the parentheses use all the time. Maybe I need to say that better?

here's a *really* rough first pass, i'm sure the end result would need some hand tweaking:

Quoted 7 lines

You can certainly send such (generated) patches to Andrew or other subsystem maintainers if you'd like, but I'm more interested in not adding more crud to the tree in the future.

IOW, sure, we prefer sizeof(foo) to sizeof foo, but the latter isn't killing us. If someone is there making other changes, it would be OK to change that also.

the advantage to standardizing what's there is that it makes it easier to make subsequent changes. as a perfect example, because there are several variations to the use of "sizeof", trying to catch every combination that might be replaceable by the use of ARRAY_SIZE() is just that much harder since you'd have to (as i had to) use regular expressions to check for every variant -- parentheses or no parentheses? space after the word or not? internal spaces within the parentheses?

all that variation makes global changes for more useful stuff a real pain.

rday

#17 lore raw
In reply to Randy Dunlap
Quoted 2 lines

Outside of comments, documentation and except in Kconfig, spaces are never used for indentation, and the above example is deliberately broken.

---

I realize it isn't text you added, but what's that supposed to mean? Surely the 8-character indents are made up of spaces. Does it mean "spaces other than 8-space blocks"? In any case, how does it synch with the following chapter's statement that continuations " are placed substantially to the right" - isn't that done with spaces, too?

Or am I just totally spacing out on what was meant?

scott

#18 lore raw

Scott Preece wrote:
[1]

Quoted 7 lines
Quoted 3 lines

Outside of comments, documentation and except in Kconfig, spaces are
never
used for indentation, and the above example is deliberately broken.

---

I realize it isn't text you added, but what's that supposed to mean? Surely the 8-character indents are made up of spaces. Does it mean

No, the 8-character indents are made of one ASCII TAB character.

Quoted 3 lines

"spaces other than 8-space blocks"? In any case, how does it synch with the following chapter's statement that continuations " are placed substantially to the right" - isn't that done with spaces, too?

That's usually (preferably) done with tab(s). Sometimes it is done with a few spaces instead. (and we put up with it :)

Quoted 1 line

Or am I just totally spacing out on what was meant?

I take [1] to mean that this example:

	if (condition) do_this;
	  do_something_everytime;

is broken in at least 3 ways:
1/ do_this(); should be on a separate line;
2/ do_something_everytime() should not be indented more than the "if"
above it; and
3/ *if* do_something_everytime() were to be indented more than it is,
it should be done with a tab, not spaces.

Signature · 1 line
~Randy
#19 lore raw
Quoted 11 lines · Randy Dunlap

Scott Preece wrote:
[1]

Quoted 7 lines
Quoted 3 lines

Outside of comments, documentation and except in Kconfig, spaces are
never
used for indentation, and the above example is deliberately broken.

---

I realize it isn't text you added, but what's that supposed to mean? Surely the 8-character indents are made up of spaces. Does it mean

No, the 8-character indents are made of one ASCII TAB character.

----

Probably should say so, then. As it is, the only way to figure that out (other than loking at code (:)) is to infer it from the .emacs example, which doesn't come until 8 chapters later in the document.

Maybe:

Outside of comments, documentation, and Kconfig, use TAB characters for indentation. Spaces are never used for indentation, and the above example is deliberately broken in several ways, including use of spaces.

scott