With 'global variables', I mean
- Variables on namespace level
- Static data members in classes
- Static variables in functions
In a big C++ project I would like to have a mechanism (like a compiler option) to prevent such data in most parts. A compiler error or warning would be nice. Of course, at one point you have to instantiate your classes.
Conceptually we have the notion of "runnables" which is the code encapsulation. While provided by the platform project they can be 'instantiated' and connected by the downstream project. Unfortunately, since usually there was only one instance of a type, devs used a lot of globals or statics. Needless to say this isn't good practise and you run into problems when doing two instances of a class later.
It's ok to have only one build preventing this (we have GCC, Clang, VS and GHS). I guess a linker option isn't applicable as the executable is linked in the downstream project and they instantiate the 'runnables' on namespace level. Another idea would be to search the object (.o) files if they contain something for the data segment, but I'm uncertain how to do that.