Coding Guidelines
Generic Guidelines
<- ^ ->
<< ^^ >>

Numeric Literals

Use symbolic names for constants In general all numeric constants should be defined symbolic names either through C's preprocessor's #define or with a const definition.
Put digits on both sides of a floating point value Floating point literals should include digits on both sides of the decimal point.
Bad .3 27.
Good 0.3 27.0
Hexadecimal constants should use capitals "A" through "F" and small "x" Hexadecimal numbers should always have the "x" in lowercase and the letters "A" through "F" in uppercase. This will promote the hexadecimal literal number to look more like a constant instead of a variable. Another good rule of thumb is to always make a hexadecimal number an even number of characters.
Bad 0Xace 0xbad0
Good 0x0ACE 0xBAD0
Long word constants should use capital "L" suffix Long int numbers should be followed by an uppercase "L" since a lowercase "l" could be confused with the number one ("1").
Bad 1111l
Good 1111L

String Literals

Prefer string resources to string literals It is preferred to store displayable strings in a string resource so they can be changed or localized without recompiling the program.
Use stringation to handle long strings
char  someComment[] =       /* POOR */
"some multiple line\n\
description that gets\n\
continued on several lines";

char  someComment[] =       /* GOOD */
        "some multiple line\n"
        "description that gets\n"
        "continued on several lines";
Avoid using actual tabs in string literals Instead of using actual tabs use the tab escape ("\t") in string literals

<- ^ ->
<< ^^ >>
Last modified: 25 May 2009
copyright 2004 Bear Consulting Group