Fri Apr 14 16:53:14 2023 UTC ()
style: don't require sorting variables in functions

Sorting the variables by size would be platform-dependent and thus is
not possible.

Sorting the variables alphabetically may or may not make the code easier
to read, and the example given below that rule doesn't follow it,
otherwise the correct order would be 'eight, eleven, nine, ten,
thirteen, twelve'.

https://mail-index.netbsd.org/tech-userlevel/2023/04/11/msg013749.html


(rillig)
diff -r1.70 -r1.71 src/share/misc/style

cvs diff -r1.70 -r1.71 src/share/misc/style (expand / switch to unified diff)

--- src/share/misc/style 2023/04/11 14:22:10 1.70
+++ src/share/misc/style 2023/04/14 16:53:13 1.71
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: style,v 1.70 2023/04/11 14:22:10 riastradh Exp $ */ 1/* $NetBSD: style,v 1.71 2023/04/14 16:53:13 rillig Exp $ */
2 2
3/* 3/*
4 * The revision control tag appears first, with a blank line after it. 4 * The revision control tag appears first, with a blank line after it.
5 * Copyright text appears after the revision control tag. 5 * Copyright text appears after the revision control tag.
6 */ 6 */
7 7
8/* 8/*
9 * The NetBSD source code style guide. 9 * The NetBSD source code style guide.
10 * (Previously known as KNF - Kernel Normal Form). 10 * (Previously known as KNF - Kernel Normal Form).
11 * 11 *
12 * from: @(#)style 1.12 (Berkeley) 3/18/94 12 * from: @(#)style 1.12 (Berkeley) 3/18/94
13 */ 13 */
14/* 14/*
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 */ 20 */
21 21
22/* 22/*
23 * Source code revision control identifiers appear after any copyright 23 * Source code revision control identifiers appear after any copyright
24 * text. Use the appropriate macros from <sys/cdefs.h>. Usually only one 24 * text. Use the appropriate macros from <sys/cdefs.h>. Usually only one
25 * source file per program contains a __COPYRIGHT() section. 25 * source file per program contains a __COPYRIGHT() section.
26 * Historic Berkeley code may also have an __SCCSID() section. 26 * Historic Berkeley code may also have an __SCCSID() section.
27 * Only one instance of each of these macros can occur in each file. 27 * Only one instance of each of these macros can occur in each file.
28 * Don't use newlines in the identifiers. 28 * Don't use newlines in the identifiers.
29 */ 29 */
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__COPYRIGHT("@(#) Copyright (c) 2008\ 31__COPYRIGHT("@(#) Copyright (c) 2008\
32 The NetBSD Foundation, inc. All rights reserved."); 32 The NetBSD Foundation, inc. All rights reserved.");
33__RCSID("$NetBSD: style,v 1.70 2023/04/11 14:22:10 riastradh Exp $"); 33__RCSID("$NetBSD: style,v 1.71 2023/04/14 16:53:13 rillig Exp $");
34 34
35/* 35/*
36 * VERY important single-line comments look like this. 36 * VERY important single-line comments look like this.
37 */ 37 */
38 38
39/* Most single-line comments look like this. */ 39/* Most single-line comments look like this. */
40 40
41/* 41/*
42 * Multi-line comments look like this. Make them real sentences. Fill 42 * Multi-line comments look like this. Make them real sentences. Fill
43 * them so they look like real paragraphs. 43 * them so they look like real paragraphs.
44 */ 44 */
45 45
46/* 46/*
@@ -343,30 +343,30 @@ main(int argc, char *argv[]) @@ -343,30 +343,30 @@ main(int argc, char *argv[])
343 * prefer returning from it, than calling exit. 343 * prefer returning from it, than calling exit.
344 */ 344 */
345 return EXIT_SUCCESS; 345 return EXIT_SUCCESS;
346} 346}
347 347
348/* 348/*
349 * The function type must be declared on a line by itself 349 * The function type must be declared on a line by itself
350 * preceding the function. 350 * preceding the function.
351 */ 351 */
352static char * 352static char *
353function(int a1, int a2, float fl, int a4) 353function(int a1, int a2, float fl, int a4)
354{ 354{
355 /* 355 /*
356 * When declaring variables in functions declare them sorted by size, 356 * When declaring variables in functions, multiple variables per line
357 * then in alphabetical order; multiple ones per line are okay. 357 * are okay. If a line overflows reuse the type keyword.
 358 *
358 * Function prototypes should go in the include file "extern.h". 359 * Function prototypes should go in the include file "extern.h".
359 * If a line overflows reuse the type keyword. 
360 * 360 *
361 * Avoid initializing variables in the declarations; move 361 * Avoid initializing variables in the declarations; move
362 * declarations next to their first use, and initialize 362 * declarations next to their first use, and initialize
363 * opportunistically. This avoids over-initialization and 363 * opportunistically. This avoids over-initialization and
364 * accidental bugs caused by declaration reordering. 364 * accidental bugs caused by declaration reordering.
365 */ 365 */
366 struct foo three, *four; 366 struct foo three, *four;
367 double five; 367 double five;
368 int *six, seven; 368 int *six, seven;
369 char *eight, *nine, ten, eleven, twelve, thirteen; 369 char *eight, *nine, ten, eleven, twelve, thirteen;
370 char fourteen, fifteen, sixteen; 370 char fourteen, fifteen, sixteen;
371 371
372 /* 372 /*