Hungarian naming rules
A few years ago, Charles Simonyi (who later became a well-known programmer at Microsoft) designed a post-fix-based naming method known as "Hungary notation" to remember him. his idea is to give each identifier a prefix based on its meaning. microsoft later adopted this idea to give each identifier a prefix to describe its data type. therefore, the prefix of the integer variable is N, the long integer variable is NL, the numeric array variable is ca, and the string (character array ending with an empty type) is prefixed with Sz. these names may be odd. for example, lpszfoo indicates that "foo" is a long integer pointer to a string ending with an empty character.
The advantage of this method is that you can identify the type of a variable by its name, instead of looking for its definition. unfortunately, this method not only bypasses the variable name, but also makes it very difficult to change the variable type. in windows3.1, the integer variable is 16 in width. if we use an integer variable at the beginning, but after using the 30---40 function, we find that the width of the integer variable is not enough. In this case, we should not only change the type of this variable, in addition, you need to change the variable name in the 30--40 functions.
Because it is impractical, no one except some stubborn windows programmers can use "Hungary notation. there is no doubt that it still exists on some occasions, but most people have abandoned it now. generally, the input prefix is a bad idea because it binds the variable together with its type.
The Hungary method is generally advantageous for functions with less than 30 rows.
Especially for interface programming, it has advantages.
However, with strong algorithm requirements, especially many abstract C ++ programs, the Hungarian method is a disaster.
See where you are using it.
Now we have good ide tools, such as Vc and sourceinsight.
When you select a variable, the system will automatically prompt you for its declaration and definition.
There is no need for the Hungarian naming law.
This is nothing more than for better program readability.
In fact, good code writing habits are more important than forcing the Hungarian naming method.
Systematic. Integrity. Readability. The classification should be clear. Annotations are required!
The Hungarian naming convention is a naming convention promoted by Microsoft for various types of symbols such as variables, functions, objects, prefixes, and macro definitions. The main idea of the Hungarian naming method is to add prefixes to variables and function names to enhance people's understanding of programs. It was launched by a Hungary inside Microsoft. As a result, it gradually became popular within Microsoft and spread to Windows developers around the world. The following describes the Hungarian naming method, which will be followed by the above Code style as much as possible in the subsequent examples. In other words, not all readers are required to abide by the rules, but readers are expected to follow the rules as a modern software developer.
A Array
B bool (INT) Boolean (integer)
By unsigned char (byte) unsigned characters (bytes)
C char character (byte)
CB count of bytes
Cr color reference value color (reference) Value
CX count of X (short) x set (short integer)
Dw dword (unsigned long) Dual-character (unsigned long integer)
F flags (usually multiple bit values) Sign (usually a multi-digit value)
FN Function
G _ global Global
H handle
I integer
L long integer
LP long pointer
M _ data member of a class
N short int short integer
P pointer
S string
SZ zero terminated string ending with 0
TM text metric text rules
U unsigned int unsigned integer
Ul unsigned long (ulong) unsigned long integer
W word (unsigned short) unsigned short integer
X, y x, Y coordinates (short) coordinate value/short integer
V void is empty.
The global variables of the project start with G _, and the class member variables start with M _. If the local variables are large, you can use L _ to show that they are local variables.
Prefix type example
G _ global variable g_servers
C Class or struct cdocument, cprintinfo
M _ member variables m_pdoc, m_ncustomers
List of common VC prefixes:
Prefix type Description Example
Ch char 8-character chgrade
Ch tchar 16-bit Unicode Character chname
B bool Boolean variable benabled
N int INTEGER (the size is determined by the operating system) nlength
N uint unsigned integer (the size is determined by the operating system) nlength
WWord 16-bit unsigned integer wpos
L long 32-bit signed integer 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 handle windows object handle hwnd
Lpfn (* fN) () callback function pointer callback far pointer to callback function lpfnabort
Abbreviation of Windows Object Name:
Windows Object example variable MFC class example object
Hwnd; cwnd * pwnd;
Hdlg; cdialog * pdlg;
HDC; CDC * PDC;
Hgdiobj; cgdiobject * pgdiobj;
Hpen; cpen * ppen;
Hbrush; cbrush * pbrush;
Hfont; cfont * pfont;
Hbitmap; cbitmap * pbitmap;
Hpalette; cpalette * ppalette;
Hrgn; crgn * prgn;
Hmenu; cmenu * pmenu;
Hwnd hctl; cstatic * pstatic;
Hwnd hctl; cbutton * pbtn;
Hwnd hctl; cedit * pedit;
Hwnd hctl; clistbox * plistbox;
Hwnd hctl; ccombobox * pcombobox;