Hungarian notation, named for the nationality of Microsoft programmer Charles Simonyi, is a way to name data variables so their data type is immediately apparent. This involves giving the variable an initial lowercase letter or letters that denote the type, followed by a descriptive name in mixed uppercase and lowercase, for example:
WORD wBufferSize;
DWORD dwFileSize;
Table B.4 shows Hungarian prefixes and the data types they correspond to.
Table 0.4 Hungarian Notation Naming Conventions
Prefix | Data Type |
b | BOOL (int) |
by | BYTE (unsigned char) |
c | char |
dw | DWORD (unsigned long) |
fn | function |
h | HANDLE (unsigned int) |
i | int |
l | LONG (long) |
n | short or int |
s | string |
sz | string terminated by NULL (0) |
w | WORD (unsigned int) |
x | short (when used as x coordinate or dimension) |
y | short (when used as y coordinate or dimension) |
These prefixes can also be prefaced by another letter or series of letters, listed in Table B.5, to indicate a pointer. (For a complete discussion of pointers, see Chapter 8.)
Table 0.5 Hungarian Notation Naming Conventions (Pointers)
Prefix | Data Type |
lp | long or far pointer |
np | short or near pointer |
p | pointer |
For example, the variable lpszCmdLine is a LPSTR Windows data type (far pointer to a NULL-terminated string). This variable could be declared as:
char FAR *lpszCmdLine;
or
LPSTR lpszCmdLine;
Although it takes a while to learn, Hungarian is useful for avoiding and quickly locating errors in Windows or standard C programs.