Suppose the following minimal code:
#include
char character = \'c\';
int main (void)
{
char character = \'b\';
printf(\"The current value
"shadowing" the global character
variable hides the variable from the main
function, but it will still be a part of the program.
If character
variable was declared as static
, then the compiler might warn that character
variable is never used and character
will be optimized away.
However, character
variable is not declared as static
; the compiler will assume that character
variable might be accessed externally and keep character
variable in the memory.
EDIT:
As noted by @Deduplicator, linker optimizations and settings could omit the variable from the final executable, if permitted. However, this is an edge case that won't happen "automatically".