ArduinoCore-sam icon indicating copy to clipboard operation
ArduinoCore-sam copied to clipboard

invalid conversion from 'void (*)()' to 'void (*)()' when using optimization flags with interrupts

Open MarcelUsai opened this issue 7 years ago • 1 comments

I had some toruble recently with a simple program using interrupts and optimization flags on the due:

#pragma GCC push_options
#pragma GCC optimize ("O3")
void setup() {
  Serial.begin(115200);
  pinMode(7, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(7), changeState, RISING);
}
void loop() {
  Serial.println("loop");
  delay(1000);
}
void changeState() {
  Serial.println("changed state");
}

When trying to compile with the optimization options, I get the following error:

sketch_feb02a:6: error: invalid conversion from 'void (*)()' to 'void (*)()' [-fpermissive]
attachInterrupt(digitalPinToInterrupt(7), changeState, RISING);
                                                                                                 ^
arduino-1.8.5\portable\packages\arduino\hardware\sam\1.6.11\cores\arduino/WInterrupts.h:28:6: error:   initializing argument 2 of 'void attachInterrupt(uint32_t, void (*)(), uint32_t)' [-fpermissive]
 void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode);
        ^
exit status 1
invalid conversion from 'void (*)()' to 'void (*)()' [-fpermissive]

Which seems really odd to me. When removing the first two lines of my code, it compiles fine.

I really have no clue why this happens but maybe someone here can use this. Maybe it's a bug, maybe I shouldn't have used these flags in the first place.

MarcelUsai avatar Feb 02 '18 10:02 MarcelUsai

I have absolutely the same issue. When I use 'Os' everything is ok, but with any other optimization level from 0 to 3 i get the same error.

cdutsov avatar Mar 01 '20 08:03 cdutsov