Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/share/misc/style,v rcsdiff: /ftp/cvs/cvsroot/src/share/misc/style,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.40.4.1 retrieving revision 1.50 diff -u -p -r1.40.4.1 -r1.50 --- src/share/misc/style 2007/11/06 23:13:20 1.40.4.1 +++ src/share/misc/style 2012/06/27 22:04:02 1.50 @@ -1,4 +1,4 @@ -/* $NetBSD: style,v 1.40.4.1 2007/11/06 23:13:20 matt Exp $ */ +/* $NetBSD: style,v 1.50 2012/06/27 22:04:02 riastradh Exp $ */ /* * The revision control tag appears first, with a blank line after it. @@ -25,11 +25,12 @@ * source file per program contains a __COPYRIGHT() section. * Historic Berkeley code may also have an __SCCSID() section. * Only one instance of each of these macros can occur in each file. + * Don't use newlines in the identifiers. */ #include -__COPYRIGHT("@(#) Copyright (c) 2000\n\ - The NetBSD Foundation, inc. All rights reserved.\n"); -__RCSID("$NetBSD: style,v 1.40.4.1 2007/11/06 23:13:20 matt Exp $"); +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: style,v 1.50 2012/06/27 22:04:02 riastradh Exp $"); /* * VERY important single-line comments look like this. @@ -76,7 +77,12 @@ __RCSID("$NetBSD: style,v 1.40.4.1 2007/ /* * Kernel include files come first. */ -#include /* Non-local includes in brackets. */ +#include /* first, */ +#include /* next, */ +#include /* and then the rest, */ +#include /* sorted lexicographically. */ +#include +#include /* Non-local includes in brackets. */ /* * If it's a network program, put the network include files next. @@ -90,7 +96,7 @@ __RCSID("$NetBSD: style,v 1.40.4.1 2007/ /* * Then there's a blank line, followed by the /usr include files. - * The /usr include files should be sorted! + * The /usr include files should be sorted lexicographically! */ #include #include @@ -109,7 +115,7 @@ __RCSID("$NetBSD: style,v 1.40.4.1 2007/ /* * ANSI function declarations for private functions (i.e. functions not used - * elsewhere) and the main() function go at the top of the source module. + * elsewhere) and the main() function go at the top of the source module. * Don't associate a name with the types. I.e. use: * void function(int); * Use your discretion on indenting between the return type and the name, and @@ -120,8 +126,7 @@ __RCSID("$NetBSD: style,v 1.40.4.1 2007/ static char *function(int, int, float, int); static int dirinfo(const char *, struct stat *, struct dirent *, struct statfs *, int *, char **[]); -static void usage(void); -int main(int, char *[]); +static void usage(void) __dead; /* declare functions that don't return dead */ /* * Macros are capitalized, parenthesized, and should avoid side-effects. @@ -354,15 +359,28 @@ function(int a1, int a2, float fl, int a * not: * !(p = f()) * + * The notable exception here is varyadic functions. Since our + * code is designed to compile and work on different environments + * where we don't have control over the NULL definition (on NetBSD + * it is defined as ((void *)0), but on other systems it can be + * defined as (0) and both definitions are valid under ANSI C), it + * it advised to cast NULL to a pointer on varyadic functions, + * because on machines where sizeof(pointer) != sizeof(int) and in + * the absence of a prototype in scope, passing an un-casted NULL, + * will result in passing an int on the stack instead of a pointer. + * * Don't use `!' for tests unless it's a boolean. * E.g. use "if (*p == '\0')", not "if (!*p)". * * Routines returning ``void *'' should not have their return * values cast to more specific pointer types. * + * Prefer sizeof(*var) over sizeof(type) because if type changes, + * the change needs to be done in one place. + * * Use err/warn(3), don't roll your own! */ - if ((four = malloc(sizeof(struct foo))) == NULL) + if ((four = malloc(sizeof(*four))) == NULL) err(1, NULL); if ((six = (int *)overflow()) == NULL) errx(1, "Number overflowed."); @@ -395,7 +413,7 @@ dirinfo(const char *p, struct stat *sb, /* * To printf quantities that might be larger that "long", include * , cast quantities to intmax_t or uintmax_t and use - * PRI?MAX constants, which may be found in . + * PRI?MAX constants. */ (void)printf("The size of %s is %" PRIdMAX " (%#" PRIxMAX ")\n", p, (intmax_t)sb->st_size, (uintmax_t)sb->st_size); @@ -417,7 +435,7 @@ dirinfo(const char *p, struct stat *sb, /* * Functions that support variable numbers of arguments should look like this. * (With the #include appearing at the top of the file with the - * other include files). + * other include files.) */ #include @@ -428,7 +446,7 @@ vaf(const char *fmt, ...) va_start(ap, fmt); STUFF; - va_end(ap); + va_end(ap); /* No return needed for void functions. */ }