Other Coding Rules: Difference between revisions

From OpenMW Wiki
Jump to navigation Jump to search
No edit summary
Line 22: Line 22:


== C++11 ==
== C++11 ==
The use of C++11 is on hold for now, until the OS X situation has been sorted out.


We allow a subset of C++11. This subset is determined by the compilers we need to support:
We allow a subset of C++11. This subset is determined by the compilers we need to support:

Revision as of 13:34, 13 January 2013

Namespaces

We prefer fully qualified names (e.g. std::cout).

Using directives (e.g. "using namespace std") are not welcome. Using directives in headers will result in the code being rejected.

Using declarations (e.g. "using std::cout") are tolerated, but should be used only in the innermost possible scope (i.e. usually function scope). Fully qualified names are still preferred.

Do not declare any names in the global namespace (the only exception to this rule is the file which contains the main() function of an executable).

Other Pieces of Advice

  • Prefer C++ means over C means. In particular:
    • Do not use the preprocessor for purposes other than conditional compiling (this includes include guards)
    • Use C++ streams instead of C I/O
    • Use new/delete instead of malloc/free (but usage of new/delete should also be limited, see below)
  • Prefer STL-container over raw arrays and new[]/delete[].
  • Use new/delete only when necessary. Prefer automatic storage duration.
  • Throw exceptions instead of retuning error codes.
  • When returning a pointer, don't return a 0-pointer in case of an error (returning a 0-pointer is still valid, if it does not represent an error situation).
  • Remember the Rule of Three.

C++11

The use of C++11 is on hold for now, until the OS X situation has been sorted out.


We allow a subset of C++11. This subset is determined by the compilers we need to support:

There are currently:

  • gcc 4.4
  • MSVC 2010
  • CLang 3.0

And here is the list of available features:

  • decltype
  • auto
  • New function declaration syntax (the -> at the end of a function)
  • Right Angle Brackets (>>)
  • R-Value references, std::move
  • static_assert