Skip to content

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

@MarcelUsai

Description

@MarcelUsai

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions