Back to libut API Reference


    #include "libut/ut.h"
    int UT_var_create(char *name, char *desc, UT_var_type type, initial);


This function creates a configuration variable having the given name, description desc, and type, and sets its initial value.

type must be one of the pre-defined constants UT_var_int, UT_var_double, or UT_var_string. This determines the type of the following initial value which must be an int, double or char*, respectively.

Warning: Use decimals (e.g., pass 1.0 instead of 1) when setting a a UT_var_double type to a literal initial value. This is necessary in a variable-length argument list, as the compiler cannot tell 1 is meant as a double unless it is passed as 1.0. The binary format of int and double are completely different and the value will be set incorrectly if a double is not passed where it is expected. (The same issue can be observed using printf(3). The code printf("1 is not %f", 1); prints ``1 is not -1.998432''!)

Once created the value of the configuration variable can be set to a new value in the control port or configuration file using the var command, or by C code using UT_var_set(3).

The desc parameter is a description of the variable, displayed in the var control port command output to make it easier to identify what each variable does. Both name and desc are copied, and silently truncated if too long.


The function always returns 0.


There is no protection against defining a configuration variable more than once.


The var control port command lists and sets the configuration variables.


UT_var_set(3), UT_var_get(3), UT_var_bindc(3), UT_var_reg_cb(3), UT_var_restrict(3)


Troy D. Hanson <>