C代码中的命名方式总结和改进
變量的命名前后綴規則如下(這是匈牙利命名法的前后綴格式,以后其他地方使用上述的總結,前后綴使用匈牙利的):
The type prefix indicates the data type of the variable.
| b | boolean | bool bHasEffect; | 
| c (or none*) | class | Creature cMonster; | 
| ch | char (used as a char) | char chLetterGrade; | 
| d | double, long double | double dPi; | 
| e | enum | Color eColor; | 
| f | float | float fPercent; | 
| n | short, int, long char used as an integer  | int nValue; | 
| s | struct | Rectangle sRect; | 
| str | C++ string | std::string strName; | 
| sz | Null-terminated string | char szName[20]; | 
The following type modifiers are placed before the prefix if they apply:
| a | array on stack | int anValue[10]; | 
| p | pointer | int* pnValue; | 
| pa | dynamic array | int* panValue = new int[10]; | 
| r | reference | int rnValue; | 
| u | unsigned | unsigned int unValue; | 
The following scope modifiers are placed before the type modifier if they apply:
| g_ | global variable | int g_nGlobalValue; | 
| m_ | member of class | int m_nMemberValue; | 
| s_ | static member of class | int s_nValue; | 
補充:
- p ---------for a pointer. A pfoo would be a pointer to data item of type FOO
 - pp------- for a pointer to a pointer.
 - h --------for a heap handle. This is a pointer to a pointer that points at a data item recorded within a heap.
 - rg -------for an unstructured array containing data items of a certain data type. An rgfoo would be an array that contains data of type foo. Individual elements would be selected by an ifoo index variable.
 - mp -------for an array which is used to map from one data type to another.Eg. A mpdochdod would be indexed via a doc index. The expression mpdochdod[doc] would produce a handle to a document descriptor.
 - dn-------- for an array whose elements that describes a meaningful index such as an opcode. If the meaningful index were an OP type, a data structure of type EOP (entries for OP) would be defined, and a dnop array would be defined which describes what each individual op means
 
Max - added to an index data instance which records the actual size of an array or data block.
eg. the declaration of a an array of type FOO in C would be: FOO rgfoo[ifooMax];
Mac - added to an index data instance to indicate the limit of an actual usage within an array.Mac stands for current maximum. It is invariant that ifooMac <= ifooMax. ifooMac == ifooMax is the condition which is true when all entries within an array are in use.
First - added to an index or pointer which designates the first element within a range that may be validly processed
Last - added to an index or pointer which designates that last entry within a range that may be validly processed.
Lim - stands for limit. An ifooLim is equal to ifooLast + 1 and designates the location where a new foo item could be recorded in an array or data block.
轉載于:https://www.cnblogs.com/jack204/archive/2011/09/07/2170408.html
總結
以上是生活随笔為你收集整理的C代码中的命名方式总结和改进的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 如何使用ping命令检查网络故障
 - 下一篇: 转载:ASP.NET中JSON的序列化和