0

I got a lot of const here. So i need to know which ones are really needed.

I need to use a pointer to a pointer where the pointer is const and the data pointed to is const. Does the following make sense?

const int a=5;
const int* const pi=&a;
const int* const * const ppi=π  // three const here? correct?

Well it compiles without warning, and make sense to me, as ppi is const *ppi is const and **ppi is const

I need to use ppi and want as much const as possible, as i am programming for an micro controller and want the data to go to flash. I know there are are ways to force data to go to flash but i'd prefer the linker to do so automatically.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Bil_Bomba
  • 183
  • 1
  • 8
  • 1
    Yes, it makes sense. Is that the question? – Kiril Kirov Jun 10 '15 at 13:29
  • It is important to note that marking things as `const` won't necessarily put them in the flash memory of your microcontroller. – shuttle87 Jun 10 '15 at 13:35
  • What kind of MCU it is? At least some MCUs (at least AVR8) has a very special syntax to tell "it should go to Flash". – No-Bugs Hare Jun 10 '15 at 13:38
  • Thanks for the fast answers. I know there are linker specific ways to tell the data belongs to flash, but i wont it to be placed there automatically if possible. – Bil_Bomba Jun 15 '15 at 10:54

1 Answers1

0

Yes, it is OK, since you want as much const-ness as possible. However, this is going to affect the future use of these data. I am not sure however if this will make the linker to put your data in flash memory, so read this question: ARM C++ - how to put const members in flash memory?.

Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305