Next: , Previous: Output Language, Up: Options


4.4 Options for fine tuning Details in the Output Code

Most of these options are also available as declarations in the input file (see Gperf Declarations).

-K slot-name
--slot-name=slot-name
This option is only useful when option ‘-t’ (or, equivalently, the ‘%struct-type’ declaration) has been given. By default, the program assumes the structure component identifier for the keyword is ‘name’. This option allows an arbitrary choice of identifier for this component, although it still must occur as the first field in your supplied struct.
-F initializers
--initializer-suffix=initializers
This option is only useful when option ‘-t’ (or, equivalently, the ‘%struct-type’ declaration) has been given. It permits to specify initializers for the structure members following slot-name in empty hash table entries. The list of initializers should start with a comma. By default, the emitted code will zero-initialize structure members following slot-name.
-H hash-function-name
--hash-function-name=hash-function-name
Allows you to specify the name for the generated hash function. Default name is ‘hash’. This option permits the use of two hash tables in the same file.
-N lookup-function-name
--lookup-function-name=lookup-function-name
Allows you to specify the name for the generated lookup function. Default name is ‘in_word_set’. This option permits multiple generated hash functions to be used in the same application.
-Z class-name
--class-name=class-name
This option is only useful when option ‘-L C++’ (or, equivalently, the ‘%language=C++’ declaration) has been given. It allows you to specify the name of generated C++ class. Default name is Perfect_Hash.
-7
--seven-bit
This option specifies that all strings that will be passed as arguments to the generated hash function and the generated lookup function will solely consist of 7-bit ASCII characters (bytes in the range 0..127). (Note that the ANSI C functions isalnum and isgraph do not guarantee that a byte is in this range. Only an explicit test like ‘c >= 'A' && c <= 'Z'’ guarantees this.) This was the default in versions of gperf earlier than 2.7; now the default is to support 8-bit and multibyte characters.
-l
--compare-lengths
Compare keyword lengths before trying a string comparison. This option is mandatory for binary comparisons (see Binary Strings). It also might cut down on the number of string comparisons made during the lookup, since keywords with different lengths are never compared via strcmp. However, using ‘-l’ might greatly increase the size of the generated C code if the lookup table range is large (which implies that the switch option ‘-S’ or ‘%switch’ is not enabled), since the length table contains as many elements as there are entries in the lookup table.
-c
--compare-strncmp
Generates C code that uses the strncmp function to perform string comparisons. The default action is to use strcmp.
-C
--readonly-tables
Makes the contents of all generated lookup tables constant, i.e., “readonly”. Many compilers can generate more efficient code for this by putting the tables in readonly memory.
-E
--enum
Define constant values using an enum local to the lookup function rather than with #defines. This also means that different lookup functions can reside in the same file. Thanks to James Clark <jjc@ai.mit.edu>.
-I
--includes
Include the necessary system include file, <string.h>, at the beginning of the code. By default, this is not done; the user must include this header file himself to allow compilation of the code.
-G
--global-table
Generate the static table of keywords as a static global variable, rather than hiding it inside of the lookup function (which is the default behavior).
-P
--pic
Optimize the generated table for inclusion in shared libraries. This reduces the startup time of programs using a shared library containing the generated code. If the option ‘-t’ (or, equivalently, the ‘%struct-type’ declaration) is also given, the first field of the user-defined struct must be of type ‘int’, not ‘char *’, because it will contain offsets into the string pool instead of actual strings. To convert such an offset to a string, you can use the expression ‘stringpool + o’, where o is the offset. The string pool name can be changed through the option ‘--string-pool-name’.
-Q string-pool-name
--string-pool-name=string-pool-name
Allows you to specify the name of the generated string pool created by option ‘-P’. The default name is ‘stringpool’. This option permits the use of two hash tables in the same file, with ‘-P’ and even when the option ‘-G’ (or, equivalently, the ‘%global-table’ declaration) is given.
--null-strings
Use NULL strings instead of empty strings for empty keyword table entries. This reduces the startup time of programs using a shared library containing the generated code (but not as much as option ‘-P’), at the expense of one more test-and-branch instruction at run time.
--constants-prefix=prefix
Allows you to specify a prefix for the constants TOTAL_KEYWORDS, MIN_WORD_LENGTH, MAX_WORD_LENGTH, and so on. This option permits the use of two hash tables in the same file, even when the option ‘-E’ (or, equivalently, the ‘%enum’ declaration) is not given or the option ‘-G’ (or, equivalently, the ‘%global-table’ declaration) is given.
-W hash-table-array-name
--word-array-name=hash-table-array-name
Allows you to specify the name for the generated array containing the hash table. Default name is ‘wordlist’. This option permits the use of two hash tables in the same file, even when the option ‘-G’ (or, equivalently, the ‘%global-table’ declaration) is given.
--length-table-name=length-table-array-name
Allows you to specify the name for the generated array containing the length table. Default name is ‘lengthtable’. This option permits the use of two length tables in the same file, even when the option ‘-G’ (or, equivalently, the ‘%global-table’ declaration) is given.
-S total-switch-statements
--switch=total-switch-statements
Causes the generated C code to use a switch statement scheme, rather than an array lookup table. This can lead to a reduction in both time and space requirements for some input files. The argument to this option determines how many switch statements are generated. A value of 1 generates 1 switch containing all the elements, a value of 2 generates 2 tables with 1/2 the elements in each switch, etc. This is useful since many C compilers cannot correctly generate code for large switch statements. This option was inspired in part by Keith Bostic's original C program.
-T
--omit-struct-type
Prevents the transfer of the type declaration to the output file. Use this option if the type is already defined elsewhere.
-p
This option is supported for compatibility with previous releases of gperf. It does not do anything.