I came across the following code today and I was a bit surprised that it worked:-
Code:
std::string func_A ()
{
      static std::string x;

      if (!x.empty())
            return x;
      else
      {
            x = "Hello";
            return x;
      }
}

std::string func_B ()
{
      static std::string x;

      if (!x.empty())
            return x;
      else
      {
            x = "Goodbye";
            return x;
      }
}
I've simplified things slightly - but the basic point is that both functions are in the same source file and they both have a static std::string called 'x'. Being static, I guess they aren't (strictly) local variables. So how does the compiler know that they're different entities? Does it encode their signatures using the function name or something like that? If I call each function separately I do seem to get the correct string...