Automatically Indenting C++ progams
There are three popular ways of indenting C programs.
More information on these tools can be found in the docuementaion
on the web.
- is a program which does simple indenting, but is not very
tailorable. It also indents with tabs, so you must post
process with a program like expand to replace tabs
with the appropriate number of spaces.
- is a very flexible indenting tool, with lots of options about
how indenting is performed.
indent -bad -bap -nbc -br -nce -i4
indent -bad -bap -nbc -bl -nce -i4
are commands which approxomate our reccomended FPCL coding
- is an editor with on-the-fly formatting. can add a phrase like:
(defun my-c-hook nil "Simple function to setup cc-mode"
(set-variable 'c-file-style "Stroustrup")
(add-hook 'c-mode-common-hook 'my-c-hook)
to their .emacs file, or add a block like
// Local Variables:
// mode: c++
// c-file-style: "Stroustrup"
to their C++ source files to set a particular indentation style.
- free source implementations of
- cb and indent come with the SUNWSpro compiler suite
Groups doing C++ development work should choose formatting conventions
that can be enforced by automated tools like indent and emacs,
and should provide .indent.pro files for indent and parameter
comment blocks for emacs to enforce their coding style.
Groups using cvs may want to automatically apply a formatter program
on source being checked into a code repository.
We may want to reccomend that Computing Division provide binary
versions of indent for our supported platforms.