Check your return types if recompiling your code!

I just made a tiny update to software that had been running in devices untouched for 2 years. It was a trivial change and compiled without issue. However, the chip would no longer run the code, resulting in a red flashing SOS error. I then discovered that simply re-compiling and downloading my unchanged older version of the code resulted in the same. After a lot of very silly troubleshooting it turns out I had a function with no return that was declared as int, whereas it should have been void. This didn’t cause an issue in the past nor did the compiler flag it as an issue even now. It should.

I would suspect the compiler did generate a warning, but if there is no actual error you may not get to see it.

e.g.

__dummy.ino: In function 'int test(const char*)':
__dummy.ino:126:1: warning: no return statement in function returning non-void [-Wreturn-type]

If you want to check warnings on an otherwise successful build in Web IDE you can deliberately introduce an error that will break the build (e.g. a stray } at the end of your code) and then look at the SHOW RAW output.

It’s good practice to check for warnings and resolve them wherever possible before releasing the code even when they don’t appear to cause any trouble (yet).

1 Like