Let's say I have class A with only static members. One of its members is of class B
class A {
//...
static B b;
}
In the A.cpp file I initialize all static members, using their constructors.
A.cpp:
B A::b(/*constructor arguments*/);
Now, nowhere in my whole project do I ever use the variable A::b.
Does that mean that the construction of that variable may totally be omitted from the final binary file by the compiler or the linker?
Even if I never use that variable, its construction has impact to the system configuration. (It may affect peripheral registers for example).
I am not using makefiles. I am using Atmel studio for AVR uControllers.
How can I be sure that the constructor of that variable will be executed during the globals and statics initialization phase of my program?
And, in general, how can I control that? (There may be a case that I need the opposite: to make sure it doesn't get initialized unless needed somewhere)
I have the impression that the initialization code may be omitted by the linker if there is no reference of that name anywhere.
Is that true?
Does it make a difference if other static variables from the file A.cpp are used? Maybe it has to do with the automated Makefile creation by the IDE, maybe it omits the whole cpp file if nothing is referenced from within
*The A.cpp belongs to a static library which I include into the project as a .a file
Thanks!