c - Memory representation of differemt translations units -


how different translation units represented in memory?

for e.g.

//internallinkage.h static int var = 10;  //file a.h void updatestatica();  //file a.cpp #include "internallinkage.h" void updatestatica() {   var = 20; }  //file b.h void updatestaticb();  //file b.cpp #include "internallinkage.h" void updatestaticb() {     var = 30; }  //main.cpp #include "internallinkage.h" #include "classa.h" #include "classb.h" int _tmain(int argc, _tchar* argv[]) {     updatestatica();     updatestaticb();     printf("var = %d",var); } 

the output here 10 know have 3 translations units each having there own copy of static variable var. question is

  1. how these translation units maintained in memory?
  2. do have separated sections each translation unit in memory compiler can maintain static variable 'var' each translation unit?

clearly there 3 different copies of variable 'var' in memory how compiler maintain copy belongs translation unit?


Popular posts from this blog