다음을 통해 공유


코딩 스타일 규칙

코딩 스타일 규칙은 명확성과 일관성을 지원하기 위해 이 샘플 시리즈에서 사용됩니다. "헝가리어" 표기법 규칙이 사용됩니다. 이는 Win32 프로그래밍에서 일반적인 코딩 관행이 되었습니다. 여기에는 변수 이름에 변수 형식의 제안을 제공하는 변수 접두사 표기법이 포함됩니다.

다음 표에서는 일반적인 접두사를 나열합니다.

접두사 Description
a Array
b BOOL(int)
c Char
cb 바이트 수
cr 색 참조 값
Cx x 개수(약식)
dw DWORD(unsigned long)
f 플래그(일반적으로 여러 비트 값)
fn 함수
G_ 전역
h Handle
i 정수
l long
lp 긴 포인터
M_ 클래스의 데이터 멤버
n 짧은 int
p 포인터
s String
sz 0으로 종료된 문자열
tm 텍스트 메트릭
u 서명되지 않은 int
Ul unsigned long(ULONG)
w WORD(부호 없는 짧은)
x,y x, y 좌표(짧게)

 

이러한 항목은 다음과 같이 결합되는 경우가 많습니다.

접두사 조합 Description
pszMyString 문자열에 대한 포인터입니다.
m_pszMyString 클래스의 데이터 멤버인 문자열에 대한 포인터입니다.

 

다음 표에는 다른 규칙이 나열되어 있습니다.

규칙 Description
CMyClass C++ 클래스 이름에 대한 접두사 'C'입니다.
COMyObjectClass COM 개체 클래스 이름에 대한 접두사 'CO'입니다.
CFMyClassFactory COM 클래스 팩터리 이름에 대한 접두사 'CF'입니다.
IMyInterface COM 인터페이스 클래스 이름에 대한 접두사 'I'입니다.
CImpIMyInterface COM 인터페이스 구현 클래스의 접두사 'CImpI'입니다.

 

주석 헤더 블록에 대한 몇 가지 일관된 규칙은 다음과 같이 이 샘플 시리즈에서 사용됩니다.

파일 헤더

/*+===================================================================
  File:      MYFILE.EXT

  Summary:   Brief summary of the file contents and purpose.

  Classes:   Classes declared or used (in source files).

  Functions: Functions exported (in source files).

  Origin:    Indications of where content may have come from. This
             is not a change history but rather a reference to the
             editor-inheritance behind the content or other
             indications about the origin of the source.

  Copyright and Legal notices.
  Copyright and Legal notices.
===================================================================+*/

일반 주석 블록

/*--------------------------------------------------------------------
  Plain block of comment text that usually takes several lines.
  Plain block of comment text that usually takes several lines.
--------------------------------------------------------------------*/

클래스 선언 헤더

/*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C
  Class:    CMyClass

  Summary:  Short summary of purpose and content of CMyClass.
            Short summary of purpose and content of CMyClass.

  Methods:  MyMethodOne
              Short description of MyMethodOne.
            MyMethodTwo
              Short description of MyMethodTwo.
            CMyClass
              Constructor.
            ~CMyClass
              Destructor.
C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/

클래스 메서드 정의 헤더

/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  Method:   CMyClass::MyMethodOne

  Summary:  Short summary of purpose and content of MyMethodOne.
            Short summary of purpose and content of MyMethodOne.

  Args:     MYTYPE MyArgOne
              Short description of argument MyArgOne.
            MYTYPE MyArgTwo
              Short description of argument MyArgTwo.

  Modifies: [list of member data variables modified by this method].

  Returns:  MYRETURNTYPE
              Short description of meaning of the return type values.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/

내보내지 않음 또는 로컬 함수

/*F+F+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  Function: MyLocalFunction

  Summary:  What MyLocalFunction is for and what it does.

  Args:     MYTYPE MyFunctionArgument1
              Description.
            MYTYPE MyFunctionArgument1
              Description.

  Returns:  MyReturnType
              Description.
-----------------------------------------------------------------F-F*/

내보낸 함수 정의 헤더

/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
  Function: MyFunction

  Summary:  What MyFunction is for and what it does.

  Args:     MYTYPE MyFunctionArgument1
              Description.
            MYTYPE MyFunctionArgument1
              Description.

  Returns:  MyReturnType
              Description.
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/

COM 인터페이스 선언 헤더

/*I+I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I+++I
  Interface: IMyInterface

  Summary:   Short summary of what features the interface can bring to
             a COM Component.

  Methods:   MYTYPE MyMethodOne
               Description.
             MYTYPE MyMethodTwo
               Description.
I---I---I---I---I---I---I---I---I---I---I---I---I---I---I---I---I-I*/

COM 개체 클래스 선언 헤더

/*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  ObjectClass: COMyCOMObject

  Summary:     Short summary of purpose and content of this object.

  Interfaces:  IUnknown
                 Standard interface providing COM object features.
               IMyInterfaceOne
                 Description.
               IMyInterfaceTwo
                 Description.

  Aggregation: [whether this COM Object is aggregatable or not]
O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/

이러한 모든 주석 블록 규칙에는 일관된 시작 및 끝 토큰 문자열이 있습니다. 이 일관성은 어떤 방식으로 헤더의 자동 처리를 지원합니다. 예를 들어 AWK 스크립트를 작성하여 함수 헤더를 별도의 텍스트 파일로 필터링한 다음 사양 문서의 기초로 사용할 수 있습니다. 마찬가지로 지원되지 않는 AUTODUCK 유틸리티(현재 Microsoft 개발자 네트워크 개발 라이브러리 CD-ROM에서 사용 가능)와 같은 도구를 사용하여 이러한 헤더의 주석 블록을 처리할 수 있습니다.

다음 표에서는 샘플 자습서에서 사용되는 시작 및 종료 토큰 문자열을 나열합니다.

토큰 설명
/*+ 파일 헤더 시작
+*/ 파일 헤더 끝
/*- 일반 주석 블록 헤더 시작
-*/ 일반 주석 블록 헤더 끝
/*C 클래스 헤더 시작
C*/ 클래스 헤더 끝
/*M 메서드 헤더 시작
M*/ 메서드 헤더 끝
/*F 함수 헤더 시작
F*/ 함수 헤더 끝
/*나 인터페이스 헤더 시작
나*/ 인터페이스 헤더 끝
/*O COM 개체 클래스 헤더 시작
O*/ COM 개체 클래스 헤더 끝

 

이러한 헤더는 소스 파일을 신속하게 검사하기 위한 시각적 신호로도 사용할 수 있습니다. 또한 편집기에서 검색 문자열을 설정한 다음 '마지막 검색 반복'을 통해 이러한 헤더를 빠르게 찾는 경우 일부 원본 위치에 빠르게 연결할 수 있는 편의를 제공합니다.

예를 들어 검색 문자열 "M+M"은 메서드 헤더의 시작을 찾고 "M-M"은 실제 메서드 정의/구현 코드의 시작을 찾습니다.