Commonly Accepted Variable Name Formatting - C/C++

I realize that this can be a matter of preference, but I have noticed that variables names in a lot of code samples I've seen have a prefix of g_, s_, m_, or just _. Is this a commonly accepted practice, and what do these prefixes mean? Are there any others that would be good to know?

Answers


  • g_ is a global variable
  • s_ is a static
  • m_ is a member (an instance variable)
  • _ is either a member, or more specifically a private member (both usages turn up)

This is common enough that many developers know about it, although it is not (to my knowledge) universally accepted. I don't think you are missing any others.

Update: Integrating comments below for better visibility

  • _ can also be used to denote a local variable (this one really isn't "standard")
  • k can be used to denote a constant

Need Your Help

Is it possible to overload a template class?

c++ templates overloading specialization

I found that template method could be overloaded, can I do the same on template classes? If 2 template classes match a template class instantiation, we can use the parameter type in the constructo...

Log error message during stringWithContentsOfFile

ios objective-c

I am trying to read a CSV file. I have imported the file in my application, so the file is in local. When I execute this part of code below:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.