October 25, 2024
Chicago 12, Melborne City, USA
C++

Does a C pointer to volatile treat the addressed memory as volatile when it is subscripted?


Consider these two definitions:

volatile int a[10];
volatile int *p = a; 

EDIT: clarify question.

If we refer to a[3] that memory location will be treated as volatile storage, that is, the compiler will make no assumptions about it staying the same.

For an array, it is clear that the intention is that the entire contents of the array are treated as volatile.

Is it the case also in C that p[3] also refers to volatile storage, though p is declared as a pointer, and not as an array? In other words, in an expression using a "pointer to volatile", such as p[3] or *(p + 3) is the volatile "infectious", and does it apply to memory locations other than the exact one pointed to by the pointer to volatile?

I do know what it means for the compiler to treat memory as volatile.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video