warning in extern declaration

While your code contains a number of rather serious and obvious errors (already covered in other answers), the warning you put into the title of your question is a completely superfluous meaningless warning. GCC compiler is notorious for issuing useless warnings. Many of those warnings seem to be derived from someone’s incompetent and completely unsubstantiated belief that doing something is somehow “wrong”, while in reality there’s nothing wrong with it.

In your case the warning is triggered by

extern int stack_counter = 0;

declaration. Apparently, the “author” of the warning believed that extern specifier should be reserved for non-defining declarations. In this case the presence of initializer = 0 turns the declaration into a definition (and thus formally makes that extern optional). Nevertheless, there’s no error in it and, in fact, extern might be quite welcome here to emphasize the fact that stack_counter is intended to be a global variable.

Again, whether you need a global variable here or not is a different question and, again, your code contains a massive number of other errors. But the warning you seem to focus your attention on is not really worth it. Just disable this warning in compiler settings (and, please, write a rude letter about it to GCC team).

Leave a Comment