strange reboot in code that cannot be explained


I am running the following code on an Arduino Uno (see attached .zip).

I observe a strange behaviour: the board reboots, seemingly at the call of battery_controller_instance.update(); in the setup loop. This is really strange, because I put a print statement just before the call to the function, and immediately at the beginning of the function. The print at the beginning of the function never gets printed. I do not think this is due to the watchdog firing, as I can put a series of prints with 1000ms delays before the call without problem (I tried this), and the watchdog should also not fire before 8s, but reboot happens after a few 100s of ms.

Any idea why this is happening?

I am using Arduino IDE 1.6.13 to compile, on Ubuntu 16.04 (I would prefer not to install new IDEs, I do not want to mess with my installs, I will update at next Ubuntu release). (208 KB)

The print at the beginning of the function never gets printed.

It's likely it does execute the print, but very shortly after executes something with an invalid pointer, crashes and never outputs the characters. Try adding a delay() immediately after the print and see if you get a character or two before it dies.


Oooh, I understand while the debugging was not working... This is an example of the dangers of macros.

The print in the incriminated function is protected by a macro:


but the DEBUG macro is defined in parameters.h, which is not included in the header file of the cpp file that implements the function. And as it is a macro, no warning, the debug is just not included...

I guess I should use some if (debug) with debug being const static instead, then I would be warned...