B
ben
Hello All,
I am trying to make sense of a bit of syntax, is there a guru out
there that can clear this up for me.
I have a buffer declared as
static volatile u8 buffer;
and I have a pointer to that buffer declared as
static volatile u8 * volatile pBuffer;
pBuffer = &buffer; // easy right
What I am trying to achieve is to create a pointer to a buffer. I want
the pointer to be volatile and I want the buffer it is pointing to to
be volatile.
The reason I am doing this is to apply the misra guidlines so I am
already aware that becuase the pointer is volatile the code will be
forced to dereference each time it is used.
The declarations above work okay, compile and run, but I cannot
understand why the second volatile apears between the type and name "*
volatile pBuffer". If I place it before the type
static volatile u8 volatile * pBuffer; // this fails
it doesnt work. but keywords appear before the type dont they ?
Also, it may just be the crappy compiler i am using but if I declare
the pointer as a constant, pointing at a volatile buffer,
static const u8 * volatile pBuffer;
I seem to be able to assign the pointer a value at run time. This
makes no sense to me.
Can anyone add parentheis to my declarations so I can read my own code
and feel sure the volatile keyword is doing what I want it to do ?
Thanks all in advance.
I am trying to make sense of a bit of syntax, is there a guru out
there that can clear this up for me.
I have a buffer declared as
static volatile u8 buffer;
and I have a pointer to that buffer declared as
static volatile u8 * volatile pBuffer;
pBuffer = &buffer; // easy right
What I am trying to achieve is to create a pointer to a buffer. I want
the pointer to be volatile and I want the buffer it is pointing to to
be volatile.
The reason I am doing this is to apply the misra guidlines so I am
already aware that becuase the pointer is volatile the code will be
forced to dereference each time it is used.
The declarations above work okay, compile and run, but I cannot
understand why the second volatile apears between the type and name "*
volatile pBuffer". If I place it before the type
static volatile u8 volatile * pBuffer; // this fails
it doesnt work. but keywords appear before the type dont they ?
Also, it may just be the crappy compiler i am using but if I declare
the pointer as a constant, pointing at a volatile buffer,
static const u8 * volatile pBuffer;
I seem to be able to assign the pointer a value at run time. This
makes no sense to me.
Can anyone add parentheis to my declarations so I can read my own code
and feel sure the volatile keyword is doing what I want it to do ?
Thanks all in advance.