Hungarian nomenclature

xiaoxiao2021-03-06  33

This agreement is developed by Charles Simonyi born in Budapest, Hungary, which enters additional information in data and function names to enhance the program's understanding of the program. E.g:

CHAR CH; / * All character variables are started at CH * /

BYTE B; / * All bytes are crown in b * /

Long L; / * All long words are crown in l * /

For pointers pointing to a data type, you can create a type name as above, then give it

Name plus prefix letter P:

Char * PCH; / * Pointer to the CH start * /

BYTE * PB; / * Similarly * /

Long * PL;

Void * pv; / * Spelp in deliberate use * /

Char ** PPCH; / * Pointer to character pointer * /

BYTE ** PPB; / * Pointer to the byte pointer * /

Hungarian names are usually not so dedicated, but when they read them in the code, they must have a lot of letters from it.

interest. For example, when you see a variable called a PCH in a function, you don't have to look at it.

It is a pointer to the character.

In order to make the Hungarian names are more descriptitive. Or to distinguish between two variable names, you can send it in the corresponding type.

After the basic name, add a "label" starting with uppercase letters. For example, the STRCPY function has two character pointers

Parameters: One is the source pointer and the other is the destination pointer. With Hungarian naming conventions, its corresponding prototype is:

Char * STRCPY (Char * PCHTO, Char * PCHFROM); / * Prototype * /

In the above example, two character pointers have a common feature - all points to the word ending with 0

String. So in this book, whenever we use a character pointer to the string, we use a more meaningful name STR.

To represent. Therefore, the prototype of the above STRCPY is:

Char * STRCPY (Char * STRTO, CHAR * STRFROM) / * Prototype * /

This book is used to another type is the type SIZE_T in the ANSI standard. Some typical uses of this type will be given below

law:

SIZE_T SIZENEW, SIZEOLD; / *

Prototype * /

Void * malloc (size_t size); / *

Prototype * /

Void * Realloc (void * pv, size_t sizenew); / * prototype * /

The naming of functions and arrays follows the same agreement, and the name begins with the corresponding return type name, followed by one.

label. E.g:

CH = chlastKeyPressed; / * get a character * /

CH = chinputbuffer []; / * Get a character * /

CH = ChreadKeyboard; / * get a character * /

If you use Hungarian naming methods, Mall ~ and Reali ~ can be written as follows:

Void * pvNewBlock (size_t size); / * prototype * /

Void * pvresizeblock (void * pv, size_t sizenew); / * prototype * /

转载请注明原文地址:https://www.9cbs.com/read-81919.html

New Post(0)