C++编程规范和标准总结
分隔:
改变一个单词的字母为大写来区别一个新词的开始,这样可以时变量更短,是因为不使用“_”。Examples:
"匈牙利" 前缀:.
m_
my_
Variable is a member of class. Some use the prefix "my" for class member variables and "our" for class member static variables. (Also "m" and "ms" for member and member-static) I have also seen the use of "_" as both a prefix and as a suffix to denote a class member variable. If using mixed languages remember that many FORTRAN compilers use a "_" suffix. Due to C++ name mangling there will probably be no conflict when using this notation. It is a common practice but theoretically could pose a problem with mixed languages.
_
(underscore)
Note: Dangerous when mixing C with FORTRAN as FUNCTION subroutines as suffixed with "_" in the object code. compiler flag "-fno-underscore".
__
Marks an use as extension to ANSI C++. Often not compiler independant. Usually reserved for use by compiler writers so it is best toavoid the double underscore.
Note: Be careful when mixing with FORTRAN as "__" is often generated in FORTRAN object symbol names. See the f77 compiler flag "-fno-second-underscore". Also used in Microsoft "Managed C++" directives.
a
array
c
n
count / number of
cb
count bytes / number of bytes
d
Data type double
dw
Data type double word
e
an enumeration or element of an array
b
f
is
has
should
boolean
(flag)
Example: isFound
Note: accessor functions can also use these same prefixes: bool isBoolean{ return mBoolean; }
g_
g gbl
Gbl
global variable. Also used is the "::" operator. i.e. ::variable
s
s_
Static variable
h
handle
i
index to an array or STL iterator
l
long data type. i.e. "long int"
p
ptr
pointer. Sometimes "Ptr" used as suffix.
lp
pointer to long data type
ch
C character
sz
Zero terminated string. char[]
str
C++ GNU template data type "string"
u
unsigned
ev
event
min
Lowest value
first
First element
lim
array limit
cmd
Command
cmp
Compare
init
Initialize
intr
Interrupt
msg
Message
rx
Recieve
tx
Transmit
C
Prefix for a Class name. Notation used by Microsoft MFC.
Example: CAbcXyz abcXyz
Note: The instatiation begins with a lower case letter while the class definition begins with a capital letter.
_t
_Type
Type definition (typedef - suffix). Prefix with capital letter.
_Enum
Enumeration type definition suffix.
_ds
Data structure suffix.
匈牙利命名例子::
使用匈牙利命名法应该使代码更容易读而不是更复杂。有的人使用上面命名规则的一部分,如:m, _, g, s, e, b,i, n.