coding.html revision 7e985260692958285fc3c128fdb27867a865db26
99be02f9e15a3ca61b6a7c207cc7eb68dbd04817vboxsyncAn ANSI standard C compiler and library are assumed. Feel free to use any
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncANSI C feature.<P>
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncGiven a reasonable set of things to warn about (e.g. -W -Wall for gcc), the
e64031e20c39650a7bc902a3e1aba613b9415deevboxsyncgoal is to compile with no warnings.
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncAll source files should have a copyright. The copyright year(s)
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncshould be kept current. The files and the copyright year(s) should be
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncUse tabs. Spaces are only allowed when needed to line up a continued
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncexpression. In the following example, spaces used for indentation are
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncindicated with "_":
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync printf("this is going to be %s very long %s statement\n",
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync _______"a", "printf");
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncVertical whitespace is also encouraged for improved code legibility by
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncgrouping closely related statements and then separating them with a
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncsingle empty line. There should not, however, be more than one empty
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncadjacent line anywhere.
dbc4cb7b07245195230a32d42f56d7edf888fcadvboxsyncLines should not be longer than 79 characters, even if it requires
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncviolating the indentation rules to do so. Since ANSI is assumed, the
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncbest way to deal with strings that extend past column 79 is to break
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncthem into two or more sections separated from each other by a newline
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncand indentation:
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync puts("This string got very far to the "
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync "left and wrapped. ANSI catenation "
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync "rules will turn this into one
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync "long string.");
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncComments should be used anytime they improve the readability of the code.<P>
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncComments may be single-line or multiline. A single-line comment should be
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncat the end of the line of there is other text on the line, and should start
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncin the same column as other nearby end-of-line comments. The comment
6dd8f5023a9ba7588212331db90059553136fe33vboxsyncshould be at the same indentation level as the text it is referring to.
dbc4cb7b07245195230a32d42f56d7edf888fcadvboxsyncMultiline comments should start with "/*" on a line by itself. Subsequent
dbc4cb7b07245195230a32d42f56d7edf888fcadvboxsynclines should have " *" lined-up with the "*" above. The end of the comment
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncshould be " */" on a line by itself, again with the "*" lined-up with the
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncone above. Comments should start with a capital letter and end with a
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync * Private variables.
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync static int a /* Description of 'a'. */
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync static int b /* Description of 'b'. */
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync static char * c /* Description of 'c'. */
19a258565a4d24e5a0af62f626943ac9b898d957vboxsyncThe following lint and lint-like comments should be used where appropriate:
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync /* ARGSUSED */
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync /* FALLTHROUGH */
19a258565a4d24e5a0af62f626943ac9b898d957vboxsync /* NOTREACHED */
e43535ace2499e7f8ef8822186047979bd58d464vboxsync /* VARARGS */
* (Information about multiprocessing considerations here, e.g. locking
The first file to be included in a C source file must be config.h.
The config.h file must never be included by any public header file
should be used for generic variables (e.g. iteration counters, array
provided by the file; e.g., dns_rbt_* interfaces would not be declared
in a file named redblack.c (in lieu of any other dns_redblack_*