Hacker News new | ask | show | jobs
by dedosk 4496 days ago
> Marking namespace-level data as static inside a header is > almost always a bad idea.

Can anybody explain this to me with some example?

1 comments

Next sentences:

    Labeling the data as such potentially generates one instance of the
    static data inside each compilation unit, including that header. Fixing
    these issues has led to measurably smaller and faster executables.
When you include that header in two different .cpp files, which compile to two different .o files, you have that data twice, local to the .o file (compilation unit).

Now link them together and you have that data twice in the executable. You probably did not want that. (But -- as with some more of their examples -- maybe you did indeed want that?)