1

Suppose I have a class

struct X
{
  static const X  ZERO;

  int  value;

  int  square () const { return value * value; }
  ...
};

Then in one TU I define it as

const X X::ZERO { 0 };

However, other TU don't know anything about the value and so cannot, as I understand, optimize based on such knowledge, e.g. they can't say that X::ZERO.square() is 0 at compile time.

Is it possible to somehow have a static field and still have its value known to all TU for optimization purposes? C++11 is fine.

1 Answers1

0

It sounds as if you are looking for "Whole Program Optimization". In Microsoft's compiler, it goes under the name "Link Time Code Generation".

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Reason for downvote? WPO is exactly "making definitions from one TU known to all TUs for optimization purposes". – Ben Voigt Jan 25 '14 at 17:24