Hungarian Notation for C/C++
a – argument b – byte (8-bit integer) c – char (assuming you are working with text) d – double (64-bit IEEE-754 floating-point number) e – enum f – float (32-bit IEEE-754 floating-point number) g – global or static h – has-a (instance variable, i.e., this object has a value) i – int (32-bit integer) j – k – const l – long (64-bit integer) m – macro n – number of (i.e., how many) o – object (usually followed by a class name) p – pointer q – r – reference s – struct t – typedef u – union v – vector (an array) w – word (16-bit integer, the wordsize on the CPUs K&R used) x – exception (often followed by a class name) y – yes-or-no (i.e., boolean) z – size
The order of prefix elements works like this: [aght ][k ][psuv ][bcdefilnorwxyz]
The first group indicates where the variable came from. Is it an argument (a), a static variable (g), an instance variable (h), a typedef (t) or a local variable (no prefix)?
The second group indicates whether you can change the variable’s value. Is it a constant (const) variable (k), or not (no prefix)? You may need to sprinkle these into long prefixes, depending on what you declare as const. The UPPERCASE_MACRO convention was the original way C had to define symbolic constants. But now the compiler knows about these, and it’s long past time to retire this habit.
The third group indicates whether the variable is a pointer (p), a struct (s), a union (u), an array (v), or none of these (no prefix)? There can be several of these in various orders. For example, ppvs denotes a pointer to a pointer to an array of structs.
The fourth group indicates the variable’s type, where most of the prefixes are highly mnemonic. For the ones that are less so: sorry, we tried, but there are only 26 letters to work with. There are some special cases that aid in succinctness: n and z.
The n prefix is easily overused, and is often confused with z. n and z are assumed to indicate int values. If you need them to be something else, prefix them with their physical types, e.g. bn or lz.
Don’t worry if some of your prefixes become quite long. The alternative is worse.
Defining a MACRO? Once again, it’s time to retire the UPPERCASE_MACRO convention. Now, it’s mPurposefulMacro.