Next: , Previous: Autostr structure, Up: Automatic strings


10.2 Allocating and freeing automatic strings

— Function: Autostr * astr_create (void)

Dynamically allocates a ‘Autostr’ and initialises it to be the empty string. It returns a pointer to the allocated ‘Autostr’, or a null pointer if none could be allocated.

— Function: void astr_destroy (Autostr *astr)

Finalises the internal data structures of astr, and then frees it.

— Function: Autostr * astr_create_s (const char *s)

Behaves like ‘astr_create’ except that the contents of the new string are set to a copy of s immediately after initialisation.

— Function: void astr_destroy_all (Autostr *astr, ...)

Destroys any number of strings at once. Any number of ‘Autostr *’ arguments may be passed following the named argument astr. The last argument should be ‘(Autostr *) 0’, so that the library knows when to stop.1 As an example, the following section of code:

          astr_destroy_all (str1, str2, str3, str4, (Autostr *) 0);

is exactly equivalent to the following:

          astr_destroy (str1);
          astr_destroy (str2);
          astr_destroy (str3);
          astr_destroy (str4);

Footnotes

[1] Note that passing a null pointer of type ‘Autostr *’ is a requirement of the C language. If you merely use a constant zero, expect your code to fail on 64-bit machines and on some word-addressed machines.