Thread: Simple pointer question

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2

    Post 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
    Code:
                    pointer++;
    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

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    One way:
    Code:
          if ( pointer >= pc_rx_buffer + sizeof pc_rx_buffer )
          {
             pointer = pc_rx_buffer;
          }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple pointer question
    By Sharke in forum C Programming
    Replies: 2
    Last Post: 04-16-2009, 01:05 AM
  2. a pointer to a function question..
    By transgalactic2 in forum C Programming
    Replies: 17
    Last Post: 10-21-2008, 11:47 AM
  3. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:19 PM
  4. Pointer and segfaults question
    By kzar in forum C Programming
    Replies: 5
    Last Post: 09-15-2005, 09:03 AM
  5. pointer to pointer as argument question
    By Lateralus in forum C Programming
    Replies: 4
    Last Post: 07-21-2005, 05:03 PM