Skip to content

CodingGuidelines:C++

Method prototype

우선순위 규칙은 아래와 같은 원칙을 바탕으로 작성한다.

  • 기계어에 가까운 문법은 앞에 적는다.
  • 코드의 추상적인 개념 또는 프로그래밍 자체에 영향을 주는 문법은 뒤에 적는다.

위의 규칙을 적용하면 아래와 같은 내용이 만들어진다.

  1. 컴파일러에 종속적인 명령: attributes (e.g. GCC의 __attribute__((deprecated)))와 같은 키워드.
  2. 최종적으로 생성되는 기계어와 관련된 명령: inline
  3. 프로그램에 영향을 주는 범위
    1. 컴파일 시간: constexpr
    2. 정적 코드: explicit, static
    3. 동적 코드: virtual
  4. 반환값
  5. 함수이름
  6. C++11 Attribute: [[noreturn]], [[carries_dependency]]

C++ 키워드상의 순서는 아래와 같다.

attributes inline constexpr static explicit virtual [return-type] const volatile [&/&&] Method [[c++11-attributes]] (arguments) const volatile [&/&&] [throw/noexcept] override

(좀 억지스럽지만) 문법적으로 문제 없는 예제는 아래와 같다.

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
내가 만든 코딩 가이드라인.
C_cpp_code_guideline.121228.pdf
C_cpp_code_guideline.121228.docx.zip (원본 MS Office - Word 작업 파일)
MISRA C
안전한 C 코딩을 위한 가이드라인.
Joint Strike Fighter Air Vehicle C++ Coding Standard (JSF AV C++)
MISRA-C의 룰을 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