Editing C++ style guide
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 7: | Line 7: | ||
== Formatting == | == Formatting == | ||
=== Indentation === | === Indentation === | ||
Use only spaces, and indent 2 spaces at a time. | |||
We use spaces for indentation. Absolutely do not use tabs in your code. | |||
You should probably set your editor to emit spaces when you hit the tab key. | |||
=== Line Length === | |||
==== | |||
Keep the length of source lines to 79 characters or less, for maximum | |||
readability in the widest range of environments. This is inherited from | |||
the [https://www.gnu.org/prep/standards/standards.html#Formatting GNU Coding Standards]. | |||
// | |||
== Header Files == | == Header Files == | ||
Line 228: | Line 25: | ||
=== Order of Includes === | === Order of Includes === | ||
Use the following order with an empty line between each section: | |||
# config.h | # config.h | ||
# The C++ wrappers for C headers (cstdlib, cassert, etc.) | # The C++ wrappers for C headers (cstdlib, cassert, etc.) | ||
# C++ standard library headers (iostream, list, map, etc.) | # C++ standard library headers (iostream, list, map, etc.) | ||
# Other POSIX headers (sys/types.h, unistd.h, etc., no need to use {{codeline|#if defined (HAVE_FOO_H)}} if existence is guaranteed because of gnulib) | |||
# Other library header files (glpk.h, curl.h, etc., should be protected by {{codeline|#if defined (HAVE_FOO_H)}} since they may be missing on the build system) | # Other library header files (glpk.h, curl.h, etc., should be protected by {{codeline|#if defined (HAVE_FOO_H)}} since they may be missing on the build system) | ||
# Octave's liboctave headers | # Octave's liboctave headers | ||
# Octave's libinterp headers | # Octave's libinterp headers | ||
Each grouping of header files should be alphabetized unless there is some | Each grouping of header files should be alphabetized unless there is some | ||
Line 246: | Line 39: | ||
{{Path|oct-parse.in.yy}} and there is a comment in the file for that one. | {{Path|oct-parse.in.yy}} and there is a comment in the file for that one. | ||
== Other C++ features == | |||
== C++ features == | |||
=== C++11 === | |||
Do not use C++11 features. Octave is widely used in very old systems and we | |||
want them to be able to use up to date versions of Octave. Building a recent | |||
compiler in such systems is not a trivial task so the limitation must happen | |||
in Octave. See [https://lists.gnu.org/archive/html/octave-maintainers/2014-11/msg00069.html A case for C++11] in the maintainers mailing list. | |||
As of Octave 4.2, Octave's configure will enable C++11 if the compiler | |||
supports it. Still, do not use C++11 features. | |||
An exception: code that requires C++11 feature must also implement an | |||
alternative code in the absence of said feature. In such case, use a | |||
configure check. This increases maintenance a lot, must be used sparsely, | |||
and requires approval from other maintainers. | |||
#if HAVE_THIS_C11_FEATURE | |||
// code that really needs it | |||
#else | |||
// alternative code in its absence | |||
#endif | |||
This decision may be revisited in the future once cross-compiling becomes | |||
more mature. | |||
=== C++14 === | |||
Do not use C++14 features. Same reason as why C++11 features are not allowed. |