I suspect this has something to do with scope, but take this code for producing a list with an initial space and subsequent commas, as taken from Expert C Programming, Deep C Secrets by Peter van der Linden:
void generate_initializer(char * string) {
static char separator = ' ';
printf("%c %s\n", separator, string);
separator = ',';
}
Why does separator
not get reassigned when it passes by the instruction static char separator = ' ';
? I understand that 'static' is telling the compiler to allocate space for separator
that extends the length of the program and to also make its scope local only to generate_initializer()
but I would assume that the code wouldn't ignore an assignment operation such as this and would always reassign separator
as a blank space.