January 09, 2001
Hello to all SC/DMC users. It's fine to have a newsserver access again. So I use this first message to come on with a problem in the implementation of anonymous namespaces (Version 7.6B68n). This small example will show the error. It consists of 2 separate files:

--------- A.CPP -------------
#include <iostream.h>

namespace {
  int local;
}

void func();

int main()
{
   local = 1;
   cout<< "local=" << local << endl;
   func();
   cout<< "local=" << local << endl;
   return 0;
}

--------- B.CPP -------------

namespace {
  int local; // should not collide with other files
}

void func()
{
   local = 2;
}

------- end example -------


The resulting printout is

local=1
local=2

but it should be

local=1
local=1

The problem is that the compiler adds a name called unique to the namespace variable. This can maybe solved by adding a timestamp to this identifier or a combination of filename and timestamp.


	Heinz