I have this code
class IO {
public:
IO(LPC_GPIO_TypeDef* port, int pin) : _pin(pin), _port(port) {};
const int _pin;
LPC_GPIO_TypeDef* const _port;
void test() {
LPC_GPIO0->FIOSET = 0;
}
};
IO led1(LPC_GPIO0, 5);
int main() {
led1.test();
return 0;
}
When i compile it i get
text data bss dec hex filename
656 0 8 664 298 lpc17xx
I'd expect const _port and _pin variables be stored in flash since they are marked const and initialization values are known at compile time, but they are allocated in .bss section. Is there any way to make them reside in flash memory?
EDIT: I tried this:
struct IO {
LPC_GPIO_TypeDef* port;
int pin;
void test() const {
//_port->FIOSET = _pin;
LPC_GPIO0->FIOSET = 0;
}
};
const IO led1 = {LPC_GPIO0, 5};
text data bss dec hex filename
520 0 0 520 208 lpc17xx
seems to do the trick. Why doesn't it work with classes?