2.2 Identifiers [ToC] [Index]     [Skip Back] [Skip Fwd]     [Prev] [Up] [Next]

In C programming it is necessary to be careful if we expect to avoid clashes between our own names and those used by others. Any identifiers that we pick might also be used by others. The usual solution is to adopt a prefix that is applied to the beginning of every identifier that can be visible in code outside a single source file. In particular, most identifiers in a library's public header files must be prefixed.

libavl is a collection of mostly independent modules, each of which implements the table ADT. Each module has its own, different identifier prefix. Identifiers that begin with this prefix are reserved for any use in source files that #include the module header file. Also reserved (for use as macro names) are identifiers that begin with the all-uppercase version of the prefix. Both sets of identifiers are also reserved as external names1 throughout any program that uses the module.

In addition, all identifiers that begin with libavl_ or LIBAVL_ are reserved for any use in source files that #include any libavl module. Likewise, these identifiers are reserved as external names in any program that uses any libavl module. This is primarily to allow for future expansion, but see Memory Allocation and Exercise 2.5-1 for a sample use.

The prefix used in code samples in this chapter is tbl_, short for “table”. This can be considered a generic substitute for the prefix used by any of the table implementation. All of the statements about these functions here apply equally to all of the table implementation in later chapters, except that the tbl_ prefix must be replaced by the prefix used by the chapter's table implementation.

Exercises:

1. The following kinds of identifiers are among those that might appear in a header file. Which of them can be safely appear unprefixed? Why?

  1. Parameter names within function prototypes.
  2. Macro parameter names.
  3. Structure and union tags.
  4. Structure and union member names.
[answer]

2. Suppose that we create a module for reporting errors. Why is err_ a poorly chosen prefix for the module's identifiers? [answer]


Footnotes

[1] External names are identifiers visible outside a single source file. These are, mainly, non-static functions and variables declared outside a function.