function prototyp preprocessor generates bad code

After installing Arduino 1.6.11, I found that the following code (shown with line numbers):

251 //=========================================================
252 //
253 // swReset() Restarts program from beginning but does not
254 // reset the peripherals and registers
255 void
256 swReset() {
257 delay (100); // wait for any buffered Serial output to finish
258 asm volatile (" jmp 0");
259 }

compiles OK with 1.6.5, but fails to compile with 1.6.11 (and 1.6.10) with the error:

meltControl:344: error: two or more data types in declaration of ‘getAd595TempC’
float getAd595TempC(int adPin) {
^
However, by changing the declaration to read:

251 //=========================================================
252 //
253 // swReset() Restarts program from beginning but does not
254 // reset the peripherals and registers
255 void swReset() {
256 delay (100); // wait for any buffered Serial output to finish
257 asm volatile (" jmp 0");
258 }

this sketch compiles without error under versions 1.6.5 and 1.6.11 and 1.6.10.

Looking at meltcontrol.ino.cpp in the /tmp/build directory where the output of the Arduino preprocessor (which manhandles and reorganizes function prototypes) is stored, I note that the first form (compiled under 1.6.11) yields an incorrect set of function prototypes that looks like:

//=========================================================
//
// swReset() Restarts program from beginning but does not
// reset the peripherals and registers
void
#line 344 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
float getAd595TempC(int adPin);
#line 349 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
float getAd595TempF(int adPin);
#line 770 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
void doEncoderB(void);
#line 836 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
void displayMenu(char *mstring);
#line 1140 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
float doSma(float newVal);
#line 256 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
swReset() {
delay (100); // wait for any buffered Serial output to finish
asm volatile (" jmp 0");
}

Compiling the 2nd form (under 1.6.11) results in a correct set of function prototypes that look like:

//=========================================================
//
// swReset() Restarts program from beginning but does not
// reset the peripherals and registers
#line 255 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
void swReset();
#line 343 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
float getAd595TempC(int adPin);
#line 348 “/export/home/dmk/Arduino%/meltControl/meltControl.ino”
float getAd595TempF(int adPin);

AFAIK, both function DECLARATION forms are correct and, in fact, this source (attached) contains numerous other function declarations in both forms.

To me, this seems to be a parsing fault in the preprocessing step that reorganizes function prototypes and generates the .ino.cpp file. Perhaps it is getting confused by the other C preprocessor directives and possibly comments in and around these statements.

I have attached the meltcontrol.ino source file FYI. If necessary to reproduce this problem, or for debugging, I can provide the entire content of the sketch directory and libraries used - just ask.

meltControl.ino (39.4 KB)

I can’t specifically test your sketch due to not having the libraries installed but I believe this is a known issue: IDE 1.6.6 breaks sketches that use multiline function declarations. · Issue #80 · arduino/arduino-builder · GitHub which appears to have stumped the Arduino developers so far. A new system of prototype generation was added in Arduino IDE 1.6.6 which caused a lot of breakage. Most of this has been fixed by now but there are still a couple of issues left over.

You should be able to fix the issue by manually adding a prototype for the problem function above the first call.

When you post code please use code tags(</> button on the toolbar) and don’t include line numbers so we can easily copy it into the IDE.