开发者

What does the m in mVariableName mean? [duplicate]

This question already has answers here: Why do variable names often start with the letter 'm'? [duplicate] (8 answers) Closed 7 years ago. 开发者_JS百科

I've seen several occurrences in tutorials where i variables with an "m" in front of the actual name. At first I thought it meant "my" but after really keeping a lookout for these "m"'s I'm no longer sure what it means. Does anyone know where this convention comes from?


m is to indicate that it is a member variable, it is common variant on Hungarian Notation. Other common prefixes to look out for are I for interface and C for class.

Depending on the language, it is also common to prefix s for string and b to indicate a boolean.


It's commonly used to mean that variable is a member of class. For example it's useful in situations like this:

someclass::somefunc()
{
...
.
.
  m_myvar = 1;
  lvar = 2;
.
.
.
}

You can tell at a glance that m_myvar is a member of someclass but lvar is not.


One common use for m as a prefix is "member", as in a member of a class in an object-oriented language.


There is no established convention on what variable names can mean, especially their prefixes.

Basically the camel casing with the first small letter normally indicates a local variable, existing only in the current execution scope. Here m can stand for "module variable", e.g. the variable that exists only in the given module and that is not global. But this is just a guess.


It is probably a slight variant on what is called Hungarian Notation, which encodes some type information in the variable name.

As mentioned by the other posters an "m" would usually be used to indicate the variable is a class member.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜