Search code examples
arraysvolatileargument-passingstrncpy

Passing volatile array to strncpy


In my ISR I have a buffer that gets stuffed from the USART so I declared the buffer as volatile:

volatile uint8_t RxBuffer1[BUFFER_LENGTH];

Ok, no problem there. I believe that is standard practice.

Somewhere in main() I need to copy a portion of that array since the array is a circular buffer and will get obliterated at sometime in the future:

strncpy(Data, RxBuffer1, len);

Oh but this is a no no! my compiler dutifully tells me:

passing argument 2 of 'strncpy' discards 'volatile' qualifier from pointer target type

since strncpy makes 's2' a const char *

I don't think I'm doing anything that hasn't been done as standard practice. How do I do this correctly?


Solution

  • Cast the argument passed to const char *