Skip to content
Search

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.

  1. Compiler-specific directives: keywords such as attributes (e.g. GCC's __attribute__((deprecated))).
  2. Directives related to the final generated machine code: inline
  3. Scope of effect on the program
    1. Compile time: constexpr
    2. Static code: explicit, static
    3. Dynamic code: virtual
  4. Return value
  5. Function name
  6. C++11 Attribute: [[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

References


  1. Google-cpp-styleguide-ko-r3.274.pdf ↩

  2. Google-styleguide-130630-backup.zip ↩

  3. Introduction_to_Coding_Guidelines_for_Cocoa_10.1.1.362.1664.pdf ↩

author Zer0 sitemap