Background
I'm trying to create two instances of a struct. One of them will not change and is therefore declared const, but the other may be changed asynchronously, therefore I'd like to make it volatile.
Problem
I'm trying to use the const instance of the structure to initialise the volatile one. However, if I use the volatile keyword the compiler throws this error:
passing 'volatile rect' as 'this' argument of 'rect& rect::operator=(rect&&)' discards qualifiers [-fpermissive]at line 15 col 8
Reproducible example
#include <Arduino.h>
struct rect {
int x0;
int y0;
int width;
int height;
};
const rect outer = {0, 0, 10, 5};
volatile rect inner;
void setup() {
inner = {outer.x0 + 1, outer.y0 + 1,
outer.width - 2, outer.height - 2};
}
void loop() {
;
}
Omitting volatile compiles fine:
rect inner = {outer.x0 + 1, outer.y0 + 1,
outer.width - 2, outer.height - 2};
Initialising one-by-one also works, but this is exactly what I'm trying to avoid:
inner.x0 = outer.x0 + 1;
inner.y0 = outer.y0 + 1;
inner.width = 0;
inner.height = outer.height - 2;
Question
What am I missing? ... It may be related to this.