C/C++ Programming Style Guidelines
C and C++ code files follow a similar structure to the header files. These files should
contain the following information in the given order.
1. Copyright statement comment
2. Module abstract comment
3. Preprocessor directives,
#include
and
#define
4. Revision-string variable
5. Other module-specific variable definitions
6. Local function interface prototypes
7. Class/function definitions
Unlike in the header file, the implementation-file revision string should be stored as a
program variable rather than in a comment. This way ident will be able to identify the
source version from the compiled object file. For C files use:
static const char rcs_id[] __attribute__ ((unused)) =
"$Id$";
The
__attribute__
modifier is a GNU C feature that keeps the compiler from
complaining about the unused variable. This may be omitted for non-GNU projects.
For C++ files, use the following form for the revision string:
namespace { const char rcs_id[] = "$Id$"; }
Precede each function or class method implementation with a form-feed character
(Ctrl-L) so that when printed the function starts at the start of a new page.