The identifiers of the functions, tables, and constants defined by the code
generated by gperf
can be controlled through gperf
declarations
or the equivalent command-line options. This is useful for three purposes:
For this purpose, just use the available declarations or options at will.
Assume you include code generated by gperf
in a library, and to
avoid collisions with other libraries, you want to ensure that all exported
identifiers of this library start with a certain prefix.
By default, the only exported identifier is the lookup function. You can therefore use the option ‘-N’ (or, equivalently, the ‘%define lookup-function-name’ declaration).
When you use the option ‘-L C++’ (or, equivalently, the ‘%language=C++’ declaration), the only exported entity is a class. You control its name through the option ‘-Z’ (or, equivalently, the ‘%define class-name’ declaration).
gperf
generated codes in a single compilation unit.
Assume you invoke gperf
multiple times, with different input files,
and want the generated code to included from the same source file. In this
case, you have to customize not only the exported identifiers, but also the
names of functions with ‘static’ scope, types, and constants.
By default, you will have to deal with the lookup function, the hash function, and the constants. You should therefore use the option ‘-N’ (or, equivalently, the ‘%define lookup-function-name’ declaration), the option ‘-H’ (or, equivalently, the ‘%define hash-function-name’ declaration), and the option ‘--constants-prefix’ (or, equivalently, the ‘%define constants-prefix’ declaration).
If you use the option ‘-G’ (or, equivalently, the ‘%global-table’ declaration), you will also have to deal with the word array, the length table if present, and the string pool if present. This means: You should use the option ‘-W’ (or, equivalently, the ‘%define word-array-name’ declaration). If you use the option ‘-l’ (or, equivalently, the ‘%compare-lengths’ declaration), you should use the option ‘--length-table-name’ (or, equivalently, the ‘%define length-table-name’ declaration). If you use the option ‘-P’ (or, equivalently, the ‘%pic’ declaration), you should use the option ‘-Q’ (or, equivalently, the ‘%define string-pool-name’ declaration).