XC16 v1.50 "assignment discards qualifiers from pointer target type"
Hello,
I have the following structure defined in my code to implement a circular queue:
typedef struct{
PWM_BUFFER_ENTRY *head;
PWM_BUFFER_ENTRY *tail;
PWM_BUFFER_ENTRY buffer[PWM_BUFFER_SIZE];
bool enabled;
bool empty;
}PWM_BUFFER;
I have a global PWM_BUFFER declared as static and volatile like so:
static volatile PWM_BUFFER mybuffer;
I need to have it declared as volatile since it will be accessed within an ISR.
And in my initialization routine, I have the following lines of code where I'm getting the compiler warning "warning: assignment discards qualifiers from pointer target type":
mybuffer.head = mybuffer.buffer;
mybuffer.tail = mybuffer.buffer;
I think I understand
why I'm getting the warning. Since the struct is declared volatile, the head and tail pointers are also volatile. However, the pointer generated by the array name (mybuffer.buffer) is not volatile; only the data in the array is. So the compiler sees that I'm assigning a volatile pointer to a non-volatile address and isn't happy.
I get the same warnings when I "loop" the pointers back in my store and remove routines.
My question is: what exactly is the "right" way to do this? I've tried casting mybuffer.buffer as a volatile pointer but that didn't seem to help. I assume there has to be a way to implement this kind of thing without causing the compiler to throw warnings all the time.
Thanks,
Shuaah