Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commonly Accepted Variable Name Formatting - C/C++

Tags:

c++

c

variables

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?

like image 600
Jim Fell Avatar asked Dec 04 '22 10:12

Jim Fell


1 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
like image 163
Jon Avatar answered Dec 22 '22 12:12

Jon