//Nei seguenti esempi file1.cpp e file2.cpp sono compilati insieme
//(cioe' nello stesso Project)



//Esempio 1

//file1.cpp
int a = 1;        //dichiarazione var globale
int f() {a = 10;} //definizione funz. (globale)
//fine file

//file2.cpp
extern int a;       //dichiarazione var esterna
int f();            //dichiarazione di funzione
//extern int f(); puo' essere usata al posto di int f();
//extern int f(); e int f(); hanno lo stesso significato
voig g() {a = f();} // ok
//fine file


//Esempio 2

//file1.cpp
int a = 1;
int b = 2;
extern int c();
//fine file

//file2.cpp
int a;           //ERR (linker) var a dichiarata due volte!
extern double b; //ERR (linker) var b di tipo int!
extern int c;    //ERR (linker) var c non dicharata!
//fine file



//Esempio 3

//file1.cpp
int a = 1;
int f() {return a;}
//fine file

//file2.cpp
int h() {return a;}   //ERR (compilatore) var a non e' dichiarata!
int g() {return f();} //ERR (compilatore) int f() non definita!
//fine file



//Esempio 4

//file1.cpp
static int a = 1;              //var locale al file1
static int f() {return a;}     //funzione locale al file1
//fine file

//file2.cpp
static int a = 100;            //var locale al file2
static int f() {return a+100;} //funzione locale al file2
//fine file



//Esempio 5

//file1.cpp
const int a = 1;   //costante locale a
                   //nota: le costanti sono locali per default
extern const int b;//cosi rendo la costante b globale
const int b = 100;
//fine file

//file2.cpp
const int a = 100;  //costante locale al file2
extern const int b;
int f() {return b;} //uso la costante b del file 1
//fine file


//Nota: "class", "struct", "enum" sono sempre globali per questo usiamo
//               #ifndef ... #endif
//Invece "typedef" e' sempre locale.
