노무현 대통령 배너


2007. 8. 20. 15:54

헝거리안 표기법

10, 15년전 Microsoft의 개발자 중 헝가리 사람의 프로그래머가 쓰던 변수 명명법.

MS 내부에서 따라 쓰기 시작하던 것이 점차 전세계의 프로그래머들에게 널리 퍼져 이젠 프로그램 코딩시 변수 명명의 표준적인 관례가 되었다. 그러나 실제로 현장에서 일하다 보면 헝가리안 표기법을 제대로 지키는 개발자는 그리 많지 않다. 어느 정도 개발 경험을 가지고 있는 프로그래머는 물론 심지어 시중의 프로그래밍 서적에서 조차 저자마다 변수명을 개인에 따라 가지각색으로 짓고 있어서 처음 프로그램을 배우는 입문자들이 변수 명명에 대한 기준을 제대로 잡지 못하고 있는 실정이다.

그러나 변수 명명에 관한 표준화된 관례를 지켜주면 코드의 가독성을 높여줄 뿐만 아니라 예를 들어 카운터 변수를 count라고 지을지 cnt라고 지을지 고민하지 않아도 되는 편리함을 누릴 수 있다.

Prefix Data TypeDescription Example
c char character type char cLetter;
s short

iintinteger for index int iCars;
l long long type long lDistance;
f float floating point float fPercent;
d doubledouble floating point double dPercent;

u unsigned unsigned type unsigned uPercent

s static a static variablestatic short ssChoice;

bBOOL any boolean type BOOL bTrue;

byt BYTE

w WORDunsigned word WORD wCnt
dw DWORD unsigned double word DWORD dwLength

p *any pointer int *piAddr;
pfn * function pointer int (*pifnFunc)(int x, int y);
rg, a array stands for range float rgfTemp[16];
sz* Zero-terminated string of characters char szText[16];

nnumber, quantity int nNum;
x/yused as size int xWitdth, yHeight;

t structa user defined type
eenum enumerated type

g_ Global Global VariableString *g_psBuffer;
m_Member class private member variable int m_iMember;

k constant formal parameter void vFunc(const long klGalaxies)
r reference formal parameter void vFunc(long &rlGalaxies)

prg dynamically allocated arraychar *prgGrades;
v Void

h handlehandle to something hMenu

자주 쓰이는 클래스

string str

Array ary

Object ogj

Thread trd

Containercon

Component com

Vector vec

윈도우 툴킷

Layout lay

Cursor cur

Eventevt

Frame frm

Label lbl

Dialog dlg

Font fnt

Graphics grp

List lst

Window win

Dimensiondim

Image img

Format

x_xXxxxxxx

0123456789

0 : 변수의 위치를 지정한다. g(전역변수), m(멤버변수), 없음(지역변수)
1 : 0 위치에 g 나 m 을 지정한 경우 _ 을 기술한다.
2 : 자료형의 종류를 나타낸다.

3 ~ : 변수의 의미 있는 이름을 기술하며, 3 위치는 대문자를 사용한다.변수 이름이 너무 긴 경우 자음만을 기술한다.

예) g_nCnt

Example of type specific variable naming

int g_nCnt: 정수형 글로벌 카운터
unsigned char ucByte;: 한 바이트 데이타
char cChar;: 한 문자
unsigned char rgucByte[10]; : 바이트 데이타 10개
char rgcChar[10]; : 문자 데이터 10개
char szChar[16 +1]; : 문자 16개를 저장할 수 있는 문자열 공간

'프로그래밍 > C/C++' 카테고리의 다른 글

UNIX 프로그래밍 필독서  (0) 2007.08.17
#define => enum, const, inline  (0) 2007.07.19
volatile의 사용  (0) 2007.04.20
[응용] printf를 잘 쓰자  (0) 2006.08.10
[본문스크랩] Buffer에 대해서 생각해 봅시다...  (0) 2006.07.20