Reprinted from: http://blog.sina.com.cn/s/blog_8a7012cf01017h9p.html
Variable naming rules are designed to enhance the readability and ease of maintenance of your code. The following are the variable naming conventions that C + + must follow: 1, variable names can only be composed of letters (A-Z,A-Z) and Numbers (0-9) or underscores (_). 2. The first letter must be a letter or an underscore. 3. You cannot use C + + keywords to name variables to avoid conflicts. 4. Variable names are case-sensitive. Variable naming rules: First, use the shortest character to express the most accurate meaning. Second, use the variable prefix. 1, integer prefix int nId; int prefix: Nshort sId; Short prefix: sunsigned int unId//unsigned int prefix: Unlong lId; Long prefix: l 2, floating-point prefix float fvalue; Float prefix: fdouble dvalue; Double prefix: D 3, character prefix char Chchar; Char prefix: ch 4, string prefix char szpath; Char string prefix: szstring strpath; String string prefix: strcstring strpath; MFC CString class Prefix: str 5, Boolean prefix bool Bisok; BOOL type prefix: Bbool bisok; MFC BOOL Prefix: B 6, pointer-type prefix char * PPATH; Pointer prefix: P 7, array prefix int arrnnum; Array prefix: arrcstring arrstrname; Array prefix + type prefix + name 8, struct-body prefix student Txiaozhang; struct Prefix: T 9, enum prefix enum Emweek; Enumeration prefix: Em 10, byte prefix byte Byip; BYTE prefix: By 11, Word prefix DWORD Dwmsgid; Double word prefix: Dwword wmsgid; Word prefix: w 12, character pointer prefix LPCTSTR ptszname; TCHAR type is ptszlpcstr pszname; Pcszlpstr Pszname; Psz 13, STL container prefix vector vecvalue; Vector container prefix: VEC 14, RECT rectangle structure prefix rect rcchild; Rccrect rcchild///RC 15, handle prefix hwnd Hwnddlg; Hhbrush HBr; Hhpen Hpen; Hhbitmap Hbmpback; h 16, Windows color prefix colorref crfont; Cr 17, Windows DC prefix CDC dcclient; The member variables of the DC class start with M_,The variable is followed by a prefix. CString M_strname; M_ start + type prefix + name four, define a variable, in order to simplify, without affecting the meaning of the variable, you can only use the prefix. RECT RC; All global variables start with g_, followed by variables, and variables are prefixed. int g_id; G VI, define the structure, to ensure that C and C + + compatible, using typedef statements, and struct type all uppercase, beginning with t_, pointer form with Pt_ start. typedef struct TAG tstudent{int nId; CString StrName;} Student,*pstudent; STUDENT Txiaozhang; Full definition structure Seven, a variable consists of multiple words, then the first letter of each word is capitalized. int Nstudentid; CString Strstudentname; Define a class with a C or T as the class name prefix. Class Cmylistctrl;class Tmylistctrl; The MFC control binding value category or control class category needs to start with m_ and prefix. CEdit M_edt_strvalue; Edit Bound control category CListBox M_lb_nname; Listboxclistctrl M_lc_name; Listctrl; CComboBox M_cb_name; /combobox 10, the control ID is as simple as possible and indicates the type and meaning of the control. Button Idc_bnt_name; Edit Idc_edt_name; ListBox Idc_lb_name; Listctrl Idc_lc_name; ComboBox Idc_cb_name;
Xi. naming rules for variables in the project
The global variables for the project start with G_, class member variables with M_, local variables if the function is larger, you can consider using L_ to show that it is a local variable.
Prefix type example
G_ global variable G_servers
Class C or structural body cdocument,cprintinfo
M_ member Variable M_pdoc,m_ncustomers
12. Common object naming rules for Windows programming
Windows Object Example variables MFC class Example Object
HWND hwnd; cwnd* pWnd;
Hdlg Hdlg; cdialog* Pdlg;
HDC hdc; cdc* PDC;
Hgdiobj Hgdiobj; cgdiobject* Pgdiobj;
Hpen Hpen; cpen* Ppen;
Hbrush Hbrush; cbrush* Pbrush;
Hfont Hfont; cfont* Pfont;
Hbitmap Hbitmap; cbitmap* Pbitmap;
Hpalette Hpalette; Cpalette* Ppalette;
HRGN HRGN; crgn* prgn;
HMENU HMENU; cmenu* Pmenu;
HWND Hctl; cstatic* pstatic;
HWND Hctl; cbutton* pbtn;
HWND Hctl; cedit* PEdit;
HWND Hctl; clistbox* Plistbox;
HWND Hctl; ccombobox* Pcombobox;
C, c + + variable naming conventions