A few years ago, Charles Simonyi (he became a famous programmer of Microsoft), designed a prefix-based naming method, which later called "Hungarian Expression" to remember him. His thought is based on each The meaning representative of the identifier gives it a prefix. Microsoft later used this idea to give each identifier a prefix to explain its data type. Therefore, the prefix of the integer variable is n, long integer variables are NL, characters Type array variables are CAs, and strings (array ends with empty types) are prefixed in SZ. These names may be very quirky. For example: lpszfoo means "foo" is a string that points to empty characters Long integer pointer.
The advantage of this approach is that people can identify variables through the name of the variable, not to find its definition. Unfortunately, this method not only makes the variable name very winding, but also changes the change of variable types It is very difficult. In Windows3.1, the integer variable is 16 is wide. If we use a integer variable at the beginning, after the calculation of 30 --- 40 functions, it is found to use integer variable width. Not enough, then we must not only change the type of variable, but also to change this variable in this 30-40 function name.
Because unreal, there is no one in addition to some stubborn Windows programmers, there is no doubt. There is no doubt that it still exists in some cases, but most people have already abandoned it. Generally speaking The input prefix is a bad idea because it is tightly tightened with the variables.
For a function of 30 lines, Hungarian methods are generally advantageous.
Especially for interface programming, it has an advantage.
But for a strong algorithm requirement, especially if there are many abstract type C programs, Hungarian methods are simply a disaster.
See where you are using.
Now there is a good IDE tool, such as: VC, SourceInsight, etc.
Select variables, will automatically prompt you to declare and definition, so
The Hungarian nomenclature is not very necessary.
It is nothing more than the program readability.
In fact, good code writing habits are more important than force to use Hungarian nomenclature.
Systemic. Integrity. readability. Category is clear. To have a comment!
The Hungarian nomenclature is a naming specification for a variable, function, object, prefix, macro definition, and other types of symbols. The main idea of Hungarian nomenclature is: adding prefix in variables and function names to enhance people's understanding of procedures. It is used by a Hungarian in Microsoft, and it is gradually popular in Microsoft, and promotes Windows developers around the world. Here will be introduced to the Hungarian nomenclature, and the following example will try to comply with it and the above code style. Or that sentence is not asking all readers to follow, but I hope the reader will follow it as a modern software developer.
A array array
B Bool (int) Boolean (integer)
By unsigned char (byte) No symbolic characters (bytes)
C char character (byte)
CB Count of bytes bytes
Cr Color Reference Value Color (Reference) Value
CX Count of X (Short) X Collection (Short Integer)
DW DWORD (unsigned long) double word (no symbol length)
f Flags (USUALLY MULTIPLE BIT VALUES) Sign (generally multiple values)
Fn function function
G_ Global Global
H handle handle i integer integer
l Long long integer
LP Long Pointer long pointer
M_ Data Member of a Class A class of data members
N Short Int short integer
P P Pointer pointer
String string
SZ ZERO TERMINATED STRING string ends with 0
TM Text Metric Text Rules
u Unsigned int unsigned integer
UL unsigned long (ulong) unsigned long integer
W Word (unsigned short) no symbol short integer
X, Y X, Y Coordinates (Short) Coordinate Value / Short Integer
v void empty
The global variable of the project is started with G_, the class member variables use m_, and the local variables are larger, and L_ can be considered to display them to show a local variable.
Prefix type example
G_ global variable g_servers
Class C or struct cDocument, CPrintinfo
M_ member variable m_pdoc, m_ncustomers
VC common prefix list:
Prefix type description example
CH char 8-bit character chgrade
CH Tchar 16 Unicode Type Characters Chname
B Bool Boolean Variable Benabled
n int integer (whose size is determined by operating system) NLENGTH
N uint No symbol integer (its size is determined by operating system) NLENGTH
W word 16-bit unsigned integer WPOS
l Long 32 with symbolic Loffset
DW DWORD 32-bit unsigned integer DWRANGE
P * Ambient Memory Model Pointer Memory Module Pointer, Pointer Variable PDOC
LP FAR * long pointer LPDOC
LPSZ LPSTR 32-bit string pointer lpszname
LPSZ LPCSTR 32-bit constant string pointer lpszname
LPSZ LPCTSTR 32-bit Unicode Type constant pointer lpszname
H H Handle Windows Object Handle HWND
LPFN (* fn) () callback function pointer Callback Far Pointer to Callback Function LPFNABORTWINDOWS object name abbreviation:
Windows object example variable 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;
VC common macro defined naming list:
Prefix symbol type symbol example
IDR_ identifies the type IDR_MAINFRAME 1 ~ 0x6FFF shared by multiple resource sharing
IDD_ dialog resource (Dialog) IDD_SPELL_CHECK 1 ~ 0x6FFF
Hidd_ Based on the context of the dialog Hids Hidd_SPell_Check 0x20001 ~ 0x26FF
IDB_ 位 图 资 资 (Bitmap) IDB_Company_Logo 1 ~ 0x6FFF
IDC_ Cursor Resource (CURSOR) IDC_PENCIL 1 ~ 0x6FFF
IDI_ Icon Resource (ICON) IDi_Notepad 1 ~ 0x6FFF
ID_, IDM_ Toolbar or Menu Bar Command Item ID_Tools_Spelling 0x8000 ~ 0xDFFFF
HID_ command context help hid_tools_spelling 0x18000 ~ 0x1dfff
IDP_ message box prompt text resource ID_INVALID_PARTNO 8 ~ 0xDFFF
HIDP_ message box context help hidp_invalid_partno 0x30008 ~ 0x3dfff
IDS_ String Resources (STRING) IDS_COPYRIGHT 1 ~ 0x7FFF
Control Resources Idc_Recalc 8 ~ 0xDFFF in IDC_ dialog
Microsoft MFC Macro Name Specification
Name Type_AFXDLL Unique Dynamic Library (DLL) version
_ALPHA only compiles the DEC Alpha processor
_Debug includes debugging version of the diagnosis
_MBCS compile multi-byte character set
_Unicode Open Unicode in an app
Function provided by AFXAPI MFC
Callback is called by pointer
Library identifier nomenclature
Identifier value and meaning
U ANSI (N) or Unicode (U)
d Debug or release: d = debug; ignore the identifier is issued
Static library version naming specification
Library description
NAFXCWD.LIB debug version: MFC static connection library
NAFXCW.LIB Release: MFC Static Library
UAFXCWD.LIB debug version: MFC static connection library with Unicode support
UAFXCW.LIB Release: MFC Static Library Supported by Unicode
Dynamic connection library naming specification
Name type
_AFXDLL unique dynamic connection library (DLL) version
Functions provided by WinAPI Windows
New naming specification in Windows.h
Type definition description
WinAPI uses the FAR Pascal location in the API declaration, if you are writing a DLL with an exporting API population point, you can use this type in your own API.
Callback uses the location of FAR Pascal in the application callback program, such as window and dialog
LPCSTR is the same as LPSTR, just LPCSTR is used for read-only string pointers, which defines similar (Const Char Far *)
UINT-portable unsigned integer type, its size is determined by the host environment (for Windows NT and Windows 9X); it is the synonym of unsigned int
LRESULT window program returns the type of value
LPARAM declares the type used by LPARAM, LPARAM is the fourth parameter of the window program
WPARAM declares the type used by WPARAM, WPARAM is the third parameter of the window program
LPVOID general pointer type, with (void *), can be used instead of LPSTR
A section of code to comply with code style and Hungarian nomenclature is as follows:
1 #include "SY.H"
2 extern int * RGWDIC;
3 Extern Int Bsymac;
4 struct sy * psysz (char SZ [])
6 {
7 char * pch;
8 int CCH;
9 Struct Sy * psy, * psycreate ();
10 int * PBSY;
11 int CWSZ;
12 Unsigned Whash = 0;
13 PCH = SZ;
14 While (* PCH! = 0)
15 Whash = Whash <> 11 * PCH ;
16 cCH = PCH-SZ;
17 pbsy = & rgbsyhash [(whash & 077777)% cWhash];
18 for (; * pbsy! = 0; PBSY = & psy-> bsynext) 19 {
20 char * szsy;
21 szsy = (psy = (struct sy *) & rgwdic [* pbsy]) -> sz;
22 PCH = SZ;
23 While (* PCH == * Szsy )
twenty four {
25 if (* PCH == 0)
26 return (psy);
27}
28}
29 cwsz = 0;
30 IF (cch> = 2)
31 CWSZ = CCH-2 / SizeOf (int) 1;
32 * PBSY = (int *) (psy = psycreate (cwsy cwsz)) - RGWDIC;
33 Zero ((int *) psy, cwsy);
34 BLTBYTE (SZ, Psy-> SZ, CCH 1);
35 Return (PSY);
36}