const pointer to const pointer to const data

731 views Asked by At

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.

1

There are 1 answers

0
gsamaras On

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?.