Next: , Previous: , Up: Dictionaries   [Contents][Index]


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)
Function: struct variable * dict_clone_var_assert (struct dictionary *dict, const struct variable *old_var)

Creates a new variable as a clone of var, inserts the new variable into dict, and returns the new variable. 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.

Function: struct variable * dict_clone_var_as (struct dictionary *dict, const struct variable *old_var, const char *name)
Function: struct variable * dict_clone_var_as_assert (struct dictionary *dict, const struct variable *old_var, const char *name)

These functions are similar to dict_clone_var and dict_clone_var_assert, respectively, except that the new variable is named name instead of keeping old_var’s name.


Next: Deleting Variables, Previous: Accessing Variables, Up: Dictionaries   [Contents][Index]