Next: , Previous: Dictionary Variable Access, Up: Dictionaries


2.6.2 Creating Variables

These functions create a new variable and insert it into a dictionary in a single step.

There is no provision for inserting an already created variable into a dictionary. There is no reason that such a function could not be written, but so far there has been no need for one.

The names provided to one of these functions should be valid variable names and must be plausible variable names.

If a variable with the same name already exists in the dictionary, the non-assert variants of these functions return a null pointer, without modifying the dictionary. The assert variants, on the other hand, assert that no duplicate name exists.

A variable may be in only one dictionary at any given time.

— Function: struct variable * dict_create_var (struct dictionary *dict, const char *name, int width)
— Function: struct variable * dict_create_var_assert (struct dictionary *dict, const char *name, int width)

Creates a new variable with the given name and width, as if through a call to var_create with those arguments (see var_create), appends the new variable to dict's array of variables, and returns the new variable.

— Function: struct variable * dict_clone_var (struct dictionary *dict, const struct variable *old_var, const char *name)
— Function: struct variable * dict_clone_var_assert (struct dictionary *dict, const struct variable *old_var, const char *name)

Creates a new variable as a clone of var, inserts the new variable into dict, and returns the new variable. The new variable is named name. Other properties of the new variable are copied from old_var, except for those not copied by var_clone (see var_clone).

var does not need to be a member of any dictionary.