@cvirus:destroy(char *str) is the only one on the list that doesn't have to be implemented as a function. It would only add function call overhead to the resultant C code. It had better be implemented as a macro:
#define destroy(s) free((void*)(s))C provides two ways to create a function local string:
1) directly on the function stack in the form of a fixed size character array, e.g.
char s[128] = "bla-bla";in which case it needs no special freeing because it's going to be destroyed together with the function stack automatically on function return; and
2) as a character pointer on the function stack that would point to a memory chunk allocated elsewhere, e.g.
char *s = (char*)malloc(128); // => uninitialized; (char*)calloc(128,1) => initialized with 0'sin which case it must be freed explicitly before the function returns if only the pointer value
s isn't returned by the function itself for use somewhere else in the program code. If this isn't done, then the pointer value
s will be lost together with the function stack on function return but the chunk will still hang in memory forever unallocatable due to the exact value having been irrevocably lost.
Variant 1 is seldom used because the default stack size is typically 1MB for the entire program and it can be exhausted very quickly if the function calls are nested deeply in one another or are recursive, especially if the character arrays are large.
In short, the C-Basic programmer should behave exactly like a C programmer would following the rules of proper memory management. Further reference materials on this topic are likely to be found in C programming manuals. You may very well
start here.