## Wednesday, January 30, 2008

Was asked before and I thought I was clear.
#include "Car.hpp"
int a = 2;

int main()
{
foo();
return 0;
}
// following is Car.cpp file, Car.hpp includes declear
#include "Car.hpp"
extern int a;
void foo()
{
printf ("%d\n",  a);
}

the visibility of a is global across all translation units. But if you say instead:

static int a = 2;

all you’ve done is change the visibility, a can only be seen in main file. Compile error happens. Look at the following two functions:

extern void foo();
static void foo();

The first one is the same as the unadorned declaration. The 2nd one means foo() is visible only within this translation unit – this is sometimes called file static.