C++ and new keyword

I think SimpleFOC has some non-initialized variables that only cause trouble with the new c++ keyword.

BLDCMotor motor(7);  // OK


BLDCMotor* motor = new BLDCMotor(7); // Not OK!

with the latter I have found that I have a bunch of hard to debug issues which I think are down to uninitialized (random initialiazed?) variables within some of the SimpleFOC classes.
I’ve found a couple of them, adding the following fixes things:

driver->pwm_frequency = NOT_SET;  // otherwise motor doesn't spin with 6PWM
motor->shaft_angle = 0.0;  //  angle_openloop sometimes has ovf - not entirely sure this is the fix 

but I suspect there are more.

I can do a pull request for these two but I’m not a c++ expert and was wondering if someone could shed some light as to why there might be a difference.

The first approach works great in simple arduino ino files or from main.cpp but as my code base is getting more complex.

it’s best if you never expect c++ to initialize anything. sometimes it does which is annoyingly inconsistent. the compiler settings, linker and runtime all have a say in this matter.

I think your fixes are the correct way this should be handled, everthing should be initialized to some known default. has anyone tried a linter or other tool to find these bugs?

Are we all c++11? That allows initialization in header files rather than constructor.

I did a search and Arduino started setting gnu++11 build flag about 5 years ago.

If not I’ll add what i find to constructor.