In general, Hungarian notation names a variable with a lower-case prefix to identify the class or usage of the variable. There is no such thing as standard HN, so the point here is to create a consistent notation system. In this class, we'll use the following standards.
c: signed character uc: unsigned character i: integer ui: unsigned integer si: short integer li: long integer n: an integer number where the actual size is irrelevant f: float d: double s: string of characters sz: string of characters, terminated by a null character b: an integer or character being used as a boolean value by: single byte ct: an integer being used as a counter or tally p: pointer to a structure or general void pointer pfs: file stream pointer pfn: pointer to a function px: pointer to a variable of class x, e.g. pi, pf, pli
These prefixes are combined with an identifying name where each significant part begins with a capital letter:
nUserChoice - holds the selection from a numeric menu
cUserChoice - holds the selection from an alphabetic menu
szFileName - a zero-terminated string with a file name in it
pfsUnsortedNumbers - file pointer to a data file
ctBytesProcessed - counter of work done
ProcessRecord()
GetUserChoice()
HandleError()
If you DO know Hungarian, and notice anything wrong with this guide, please send me mail. Thanks.
Tag | Description |
---|---|
f | Boolean flag. The qualifier should be used to describe the condition that causes the flag to be set (for example, fError might be used to indicate a variable that is set when an error condition exists, and clear when there is no error). The actual data representation may be a byte, a word, or even a single bit in a bitfield. |
ch | A single-byte character. |
w | A machine word (16 bits on Win3.1 X86 machines). This is a somewhat ambiguous tag, and it is often better to use a more specific name. (For example, a word that represents a count of characters is better referred to as a cch than as a w. See the prefixes section for an explanation of the cch notation.) |
b | A byte (typically 8 bits). See the warnings for w. |
l | A long integer (typically 32 bits). See the warnings for w. |
u | An unsigned value. Usually more accurately used as a prefix with one of the integer types described above. For example, a uw is an unsigned word. |
r | A single-precision real number (float) |
d | A double-precision real number (double) |
bit | A single bit. Typically this is used to specify bits within other types; it is usually more appropriate to use f. |
v | A void. (Rather C-specific, meaning the type is not specified.) This type will probably never be used without the p prefix. This would usually be used for generic subroutines (such as alloc and free) that work with pointers but don't need to refer to the specific type of data referenced by those pointers. |
st | A Pascal-type string. That is, the first byte contains the length of the string, and the remainder contains the actual characters in the string. |
sz | A null-terminated (C-style) string. |
fn | A function. This will almost always have a p prefix, as about the only useful thing you can do with a function (from a variable's perspective) is take the address of it. |
Constructor | Description |
---|---|
p | A pointer. |
lp | A long (far) pointer. (Used on machines with a segmented architecture, such as X86's under DOS or Win3.1). |
hp | A huge pointer. (Similar to a far pointer, except that it handles crossing segment boundaries during pointer arithmetic correctly.) |
rg | An array. An rgch is an array of characters; a pch could point to a specific element in this array. (The notation comes from viewing an array as a mathematical function -- the input is the index, and the output is the value at that index. So the entire array is essentially the "range" of that function.) |
i | An index (into an array). For example, an ich could be used to index into an rgch. I've also seen this used for resource IDs under Windows (which makes sense if you think about it -- a resource ID is an index into a resource table). |
c | A count. cch could be the count of characters in the rgch. (As another example, note that the first byte of an st is the cch of that string.) |
d | The difference between two instances of a type. For example, given a type x used to represent an X-coordinate on a graph, a dx could contain the difference on the X-axis of two such coordinates. |
h | A handle. Handles are commonly used in Windows programming; they represent resources allocated by the system and handed back to the application. On other systems, a "handle" might be a pointer to a pointer, in which case it might be clearer to use a pp (or lplp if appropriate). |
mp | A specific type of array, a mapping. This prefix is followed by two types, rather than one. The array represents a mapping function from the first type to the second. For example, mpwErrisz could be a mapping of error codes (wErr) to indexes of message strings (isz). |
v | A global variable (personally I prefer g for this) |
Here are some further examples of constructors + tags:
Variable | Description |
---|---|
pch | A pointer to a character. |
ich | An index into an array of characters. |
rgsz | An array of null-terminated strings (most likely the values stored in the array are actually pointers to the strings, so you could arguably also use rgpsz). |
rgrgx | A two-dimensional array of x's. (An array of arrays of x's.) |
pisz | A pointer to an index into an array of null-terminated strings. (Or possibly a pointer to a resource ID of a string -- the real meaning should be clear within the context of the code.) |
lpcw | Far pointer to a count of words. |
The use of many variables will fall into the same basic categories, so there are several standard qualifiers:
Qualifier | Description |
---|---|
First | The first element in a set. This will often be an index or a pointer (for example, pchFirst or iwFirst). |
Last | The last element in a set. Both First
and Last refer to valid values that are in a given set, and
are often paired, such as in this sample C loop:
for (iw = iwFirst; iw <= iwLast; iw++) { ... } |
Min | The first element in a set. Similar to First, but Min always refers to the first actual element in a set, while First may be used to indicate the first element actually dealt with (if you're working with a substring, for example). |
Max | The upper limit in a set. This is NOT
a valid value; xMax is usually equivalent to xLast + 1.
The above example loop could also be written as
for (iw = iwFirst; iw < iwMax; iw++) { ... }I've also seen Lim used to indicate the limit in much the same manner. |
Mac | The current upper limit in a set. This is similar to Max, but is used where the upper limit can vary (for example, a variable length structure). |
Sav | A temporary saved value; usually used when temporarily modifying variables that you want to restore later. |
T | A temporary variable -- one which will be used quickly in a given context and then disposed of or reused. |
Src | A source. This is usually paired with Dest in copy/transfer operations. |
Dest | A destination. This is usually paired with Src. |
Structure members should simply be named the same way variables are. Since the context is usually only within the structure itself, name conflicts are less likely, so qualifiers are often not as necessary. If you have multiple instances of a variable type within the structure, you'll still need the qualifiers, of course (for example, if you're creating a structure containing name and address string records, you could name them szName and szAddress). If the language does not support seperate contexts for each structure (I think the Microsoft Macro Assembler (MASM) falls into this category, but I haven't worked with it in a few years), then the structure name is appended to the name of the member as a qualifier. (So the examples given above might be named szNameDbr and szAddressDbr if these fields appeared in the dbr structure.)
Congratulations. You've found the one page that some people might consider
semi-useful, and even then only a small segment of the software development
community. If even that much...
This World Wide Web server is a service of Telerama Public Access Internet.
Last modified: Wed Sep 18 10:54:54 1996