5

I have to maintain binary compatibility for this C++ library that I'm working on.

Currently, I have something along these lines

class Foo
{
    void Bar()
    {
        static bool flag = true;
    }
}

Will removing flag break binary compatibility of Foo?

Aside My compiler presently is VC7.1 if that matters.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445

3 Answers3

2

The static variable is not part of the function's interface, so it won't affect binary compatibility. You should be aware, none the less, that if the function is really that simple, it might have been inlined in which case unless you recompile all users you will be breaking the ODR.

Simple advice: recompile if at all possible. Make sure that it was not inlined in the original code if not possible.

David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
1

It does not break binary compatibility in the sense that something is certain to crash, or that program will not start.

However, it may well break functionality, if that method ever got inlined. Inlined versions will still access that static variable, and then code built against new header file will produce methods which do not use the static variable. It depends on code if this is a problem or not, but often it is, the static variable (which will not be used by recompiled code) probably wasn't there just for fun, and neither is the replacement (which will not be used by old inlined code).

Lesson: If you want to avoid recompilation of everything after library header modification, do not access static variables from any code in header files, or do anything else which you might want to change. Assume all code in header files may get inlined.

Related question: static variables in an inlined function

Community
  • 1
  • 1
hyde
  • 60,639
  • 21
  • 115
  • 176
0

No. It has no external visibility.

sehe
  • 374,641
  • 47
  • 450
  • 633