coding.html revision 40f53fa8d9c6a4fc38c0014495e7a42b08f52481
7aacbd685b2107670e4179689abec9cb82d972abBob Halley - Copyright (C) 1999, 2000 Internet Software Consortium.
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - Permission to use, copy, modify, and distribute this software for any
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - purpose with or without fee is hereby granted, provided that the above
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - copyright notice and this permission notice appear in all copies.
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley - WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley<!-- $Id: coding.html,v 1.13 2000/08/01 01:18:21 tale Exp $ -->
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob HalleyAn ANSI standard C compiler and library are assumed. Feel free to use any
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob HalleyANSI C feature.<P>
de9282a1eaa50764fdc2e88046f8ff3522e3092eBob HalleyGiven a reasonable set of things to warn about (e.g. -W -Wall for gcc), the
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleygoal is to compile with no warnings.
4cafb28abcaa2a485c7aac1696213435538b92edBob HalleyAll source files should have a copyright. The copyright year(s)
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleyshould be kept current. The files and the copyright year(s) should be
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob HalleyUse tabs. Spaces are only allowed when needed to line up a continued
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleyexpression. In the following example, spaces used for indentation are
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleyindicated with "_":
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley printf("this is going to be %s very long %s statement\n",
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley _______"a", "printf");
4cafb28abcaa2a485c7aac1696213435538b92edBob HalleyVertical whitespace is also encouraged for improved code legibility by
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleygrouping closely related statements and then separating them with a
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleysingle empty line. There should not, however, be more than one empty
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleyadjacent line anywhere.
de9282a1eaa50764fdc2e88046f8ff3522e3092eBob HalleyLines should not be longer than 79 characters, even if it requires
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleyviolating the indentation rules to do so. Since ANSI is assumed, the
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleybest way to deal with strings that extend past column 79 is to break
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleythem into two or more sections separated from each other by a newline
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleyand indentation:
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley puts("This string got very far to the "
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley "left and wrapped. ANSI catenation "
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley "rules will turn this into one
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley "long string.");
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob HalleyComments should be used anytime they improve the readability of the code.<P>
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob HalleyComments may be single-line or multiline. A single-line comment should be
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleyat the end of the line if there is other text on the line, and should start
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleyin the same column as other nearby end-of-line comments. The comment
4cafb28abcaa2a485c7aac1696213435538b92edBob Halleyshould be at the same indentation level as the text it is referring to.
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob HalleyMultiline comments should start with "/*" on a line by itself. Subsequent
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleylines should have " *" lined-up with the "*" above. The end of the comment
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleyshould be " */" on a line by itself, again with the "*" lined-up with the
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halleyone above. Comments should start with a capital letter and end with a
de9282a1eaa50764fdc2e88046f8ff3522e3092eBob Halley * Private variables.
7aacbd685b2107670e4179689abec9cb82d972abBob Halley static int a /* Description of 'a'. */
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley static int b /* Description of 'b'. */
* (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_*