CodingGuidelines:C++
lastmod 2021-07-11created 2016-10-1314 edits
Method prototype
The precedence rules are based on the following principles.
- Syntax closer to machine code comes first.
- Syntax that affects abstract concepts of the code or the programming itself comes later.
Applying the rules above produces the following.
- Compiler-specific directives: keywords such as attributes (e.g. GCC's
__attribute__((deprecated))). - Directives related to the final generated machine code: inline
- Scope of effect on the program
- Compile time: constexpr
- Static code: explicit, static
- Dynamic code: virtual
[[noreturn]], [[carries_dependency]] The keyword order in C++ is as follows.
attributes inline constexpr static explicit virtual [return-type] const volatile [&/&&] Method [[c++11-attributes]] (arguments) const volatile [&/&&] [throw/noexcept] override
A (somewhat contrived) syntactically valid example is as follows.
struct Temp1
{
int value = 0;
__attribute__((deprecated)) inline virtual int const volatile & dep1() const volatile && noexcept((noexcept(Temp1())))
{ return value; }
constexpr Temp1(){}
};
struct Temp : public Temp1
{
int value = 0;
constexpr Temp(){}
constexpr explicit Temp(int v) : value(v){}
__attribute__((deprecated)) inline virtual int const volatile & dep1 [[carries_dependency]] () const volatile && noexcept((noexcept(Temp()))) override
{ return value; }
__attribute__((deprecated)) inline constexpr static int dep2()
{ return 1; }
};
Documentation
- C/C++ Code Guideline (Release. 2011-11-24) - Document No.01
- A coding guideline I wrote.
-
C_cpp_code_guideline.121228.pdf - C_cpp_code_guideline.121228.docx.zip (original MS Office - Word working file)
- MISRA C
- Guidelines for safe C coding.
- Joint Strike Fighter Air Vehicle C++ Coding Standard (JSF AV C++)
- Reinterprets the rules of MISRA-C according to the rules of JSF AV C++.
-
Jsf_av_cpp_coding_standards_rev_c.pdf
See also
Favorite site
- Google C++ Style Guide (ko) Revision 3.274 1
- Textcube Coding Guidelines
- From time to time the JSF Program Office Releases briefings to the public
- google-styleguide project page 2
- LLVM Coding Standards - LLVM 7 documentation
- Introduction to Coding Guidelines for Cocoa 3