-
Simple pointer question
Hi all.
I am receiving serial data and placing it into a buffer.
In main I am using a pointer to view the elements of the buffer.
Code:
volatile char *pointer;
pointer = pc_rx_buffer;
I work my way through the buffer using
If the buffer created is,
Code:
pc_rx_buffer[PC_Rx_BUFFER_SIZE])
What is the correct way to test whether my pointer is at the last element of my buffer, so that I can reset my pointer to the beginning of my buffer?
Im sure this is quite simple, but I'm through with scratching my head about this so I thought i would just ask.
Thanks
-
One way:
Code:
if ( pointer >= pc_rx_buffer + sizeof pc_rx_buffer )
{
pointer = pc_rx_buffer;
}
-
Thanks Dave,
Thats pretty much what I was heading towards.
I just thought that it was a bit messy. Logically that is the equivalent of what I need to do.