C++ style guide: Difference between revisions

Jump to navigation Jump to search
287 bytes added ,  10 June 2020
(Extend Doxygen style guide and prettify code examples using <syntaxhighlight>.)
(5 intermediate revisions by 4 users not shown)
Line 181: Line 181:
=== std::string ===
=== std::string ===


When an empty string is required, use @qcode{""}, rather than creating an empty
When an empty string is required, use "", rather than creating an empty
string object with @code{std::string ()}.
string object with std::string ().


=== auto ===
=== auto ===
Line 221: Line 221:
Doxygen allows for a variety of commenting styles. In order to maintain uniformity across the entire project the following rules should be applied:
Doxygen allows for a variety of commenting styles. In order to maintain uniformity across the entire project the following rules should be applied:


* For Doxygen comments use only {{codeline|//!}} and NOT {{codeline|/*! ... */}}
* For Doxygen comments use only {{codeline|//!}} and NOT {{codeline|/*! ... */}}, regardless of the size of the block comment
* Use {{codeline|@}} for any [https://www.stack.nl/~dimitri/doxygen/manual/commands.html Doxygen Special Commands]
* Use {{codeline|@}} for any [https://www.stack.nl/~dimitri/doxygen/manual/commands.html Doxygen Special Commands]
* Use as little formatting as possible.  Restrict to [https://www.stack.nl/~dimitri/doxygen/manual/markdown.html Markdown] and avoid HTML-markup.
* Use as little formatting as possible.  Restrict to [https://www.stack.nl/~dimitri/doxygen/manual/markdown.html Markdown] and avoid HTML-markup.
* Do NOT use the {{codeline|@brief}} command, the first sentence will automatically be used as the summary description.
* The first sentence should describe briefly what the function does and end with a period.
* Leave a blank line between the Doxygen comment and function definition.
* Leave a blank line between the Doxygen comment and function definition.


Line 229: Line 231:


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
//! @brief Some cool function.
//! Does something interesting with its arguments.
//!
//!
//! Long comment with **bold** special commands.
//! Long comment with **bold** special commands.
Line 244: Line 246:
//! @endcode
//! @endcode


void some_function (double some_param, int another_param) {
void
some_function (double some_param, int another_param)
{
   // ...
   // ...
}
}
Line 255: Line 259:
The preferred comment mark for places that may need further attention is
The preferred comment mark for places that may need further attention is
with {{codeline|FIXME:}} comments.
with {{codeline|FIXME:}} comments.
[[Category:Development]]

Navigation menu