0

I am currently working with production code in ANSI-C, which is partly getting generated by a very intransparent toolchain (so I could not find any clear information about it).

Somewhere in the generated code the following happens:

extern const volatile int16 * const volatile Varray[20];

And the access to it:

int16 myValue = *Varray[var];

It works, this is not part of the question. I just want to know why the const volatile is written before AND after the datatype int16 *.

R. Joiny
  • 309
  • 7
  • 17
  • i prefer write it `extern int16 const volatile * const volatile Varray[20];` ;) – Stargateur Jan 09 '18 at 09:02
  • Is this the right duplicate? *I just want to know why the const volatile is written before AND after the datatype int16 *.* - OP asked this. @FelixPalmen – user2736738 Jan 09 '18 at 09:11
  • The `const` keyword tells the compiler a value should not be changed inside the code where the declaration is. The keyword `volatile` tells the compiler that the value might be changed outside the code where is the declaration. The first declaration informs the compiler about the pointer values, the second declaration informs the compiler about the pointed values. – Sir Jo Black Jan 09 '18 at 09:12
  • @coderredoc I think this question is answered implicitly when reading the linked duplicate. You just have to know what the qualifiers mean in the different places. –  Jan 09 '18 at 09:12
  • @coderredoc if the question is more semantic (like *why does the pointer **and** the data need to be volatile and const*?), it needs more context, in which case it **could** be reopened. –  Jan 09 '18 at 09:14
  • @FelixPalmen.: No it's ok. I guess OP would get a lot of help from dup itself. Thanks and good job. – user2736738 Jan 09 '18 at 09:15
  • See also: https://stackoverflow.com/questions/4592762/difference-between-const-const-volatile – Sir Jo Black Jan 09 '18 at 09:16
  • @coderredoc well Stargateur spotted it, I just "hammered" because I think it's enough for answering the question. –  Jan 09 '18 at 09:16
  • @FelixPalmen.: Yes I admit. That's alright. I will delete the answer. – user2736738 Jan 09 '18 at 09:16
  • Ok thank you all, the marked question did solve my headaches. Should've searched the issue without 'volatile', then I probably would've found the duplicate. – R. Joiny Jan 09 '18 at 09:24
  • Excuse me, in my explanation you have to exchange "The first declaration" and "the second declaration". – Sir Jo Black Jan 09 '18 at 09:29

1 Answers1

1
extern const volatile int16 * const volatile Varray[20];

This just means that both the pointer and the value are "const volatile".

So, Varray is an array of const volatile pointers which will store const volatile int16's

Jay
  • 24,173
  • 25
  • 93
  • 141