I'm new to C. I have a book in front of me that explains C's "file scope", including sample code. But the code only declares and initializes a file scoped variable - it doesn't verify the variable's scope by, say, trying to access it in an illegal way. So! In the spirit of science, I constructed an experiment.
File bar.c
:
static char fileScopedVariable[] = "asdf";
File foo.c
:
#include <stdio.h>
#include "bar.c"
main()
{
printf("%s\n", fileScopedVariable);
}
According to my book, and to Google, the call to printf()
should fail - but it doesn't. foo.exe
outputs the string "asdf" and terminates normally. I would very much like to use file scoping. What am I missing?