Hi, very sorry if this question should be too picky ... .
I have quite a bit of large "global classes" in my multi-module C++ software. (I mean a class without constructor/destructor, which is used exactly one time in the software - it is defined "globally").
As it is used only one time, I could specify the variables / functions as static or not. I was wondering, which way would create tighter code. According to my investigations I have the following rules now: - Functions should be static, except inline functions - these must NOT be static (otherwise they are not inlined any more). - Public data variables, which are heavily used outside class functions, should preferably be defined static. - Private data variables, which are mainly used inside class functions, should preferably be defined non-static.
Could some C++ expert have a look at these rules and comment them? (ok, quite ok or complete nonsense?)
PS: In some C++ languages, it seems to be possible to define a complete class as static:
static class TestClass{ ... };
As I see, this is NOT possible in Keil C++, or am I wrong?
... I first ended up using all classes non-static now.
Just then I finally recognized that in such a case I cannot use bitband member variables (see my other post from today at the end of "--bitband compiler switch fails (very strange)".
So for "one-time" classes with bitband member variables, I now would recommend to define them completely static (all members + functions static).
Sorry: One correction necessary: It is NOT required to define the class functions static. Only the struct with the bit definitions needs to be static, then bitband will work fine. This is quite convenient and safe then.