C++ constructor of static objects not called
Hello,
I am trying to use C++ in the SPC560Bxx mcu using SPC5 Studio and the free gcc vle toolchain (4.9.2).
However, it looks like constructors aren't called as I expected.
In the following example, I expect to end up in the first case of the if statement, but I end up in the else case.
class Foo {
public:
int val;
Foo() {
val = 42;
}
void do_something() {
if (val == 42) {
printf('I expect to end up here');
} else {
printf('But I end up here');
}
}
};
static Foo myObject; // this ought to call the Foo's constructor
int main(void) {
...
myObject.do_something();�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
...
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
From what I understand this is because the crt0.s doesn'tinitialize the static objects on startup.
Does anyone have a solution to my problem or aworking c++ example they can share?
#spc560b54l5 #c++11 #c++ #gcc