2

Say we have such declaration :

int **const*** k;

Then, it could be well translated literally (according to cdecl.org) to

declare k as pointer to pointer to pointer to const pointer to pointer to int

However, still, I'm not sure to understand what it does not permit? Which operation does it restrict? Could we still do

(***k)++

In other words, what is the effect of adding const there?

And... Same question for

int *const**const* k;

Which difference would it make?

Thanks!

haccks
  • 104,019
  • 25
  • 176
  • 264
Yannick
  • 830
  • 7
  • 27
  • 3
    It's good for a question, but don't do weird things in real life, everyone will hate you. – Maroun Jan 08 '14 at 15:27
  • This will help: http://stackoverflow.com/a/1143272/2171035 –  Jan 08 '14 at 15:28
  • There's a quote by someone: "The C syntax is a boon to teachers of trivia and people who like to make fun of the language, but not actually a problem". – Kerrek SB Jan 08 '14 at 15:30
  • I was waiting for someone to comment! Actually, I'm making a kind of C interpreter. Hence why I must be able to reproduct accurately even the most unusual types! Else, I wouldn't even bother asking. – Yannick Jan 08 '14 at 15:30

1 Answers1

4

still, I'm not sure to understand what it does not permit?

It does not permit the modification that ***k points to.

Could we still do

(***k)++   

No. You can't. This is because ***K is a pointer to pointer to pointer to const pointer and you can't modify it. But yes, modification to K, *k, **k is valid.

For the sake of convenience, you can understand this as follows:

int *const k;     // k is a const pointer to integer. No modification to k.  
int *const *k;    // *k is a const pointer to integer. No modification to *k.  
int *const **k;   // **k is a const pointer to integer. No modification to **k.  
int *const ***k;  // ***k is a const pointer to integer. No modification to ***k.  
int **const ***k; // ***k is a const pointer to integer. No modification to ***k.
haccks
  • 104,019
  • 25
  • 176
  • 264