avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Linked lists.


From: Theodore A. Roth
Subject: Re: [avr-gcc-list] Linked lists.
Date: Mon, 9 Dec 2002 10:32:41 -0800 (PST)

On Mon, 9 Dec 2002, Daniel Williamson wrote:

:) Hi,
:)
:) I'm implementing a linked list of structures as part of a re-configurable
:) state machine.  I can declare a pointer to the structures and it works fine.
:) However If I increment the pointer as in pointer++; Then I start going off
:) track.  I was rather hoping that incrementing the pointer in this way would
:) jump to the next defined structure in my list.

The ptr++; idiom assumes that the elements of the list are in consecutive
memory addresses. That assumption is wrong when you malloc each element
(the normal implementation of a linked list).

To get to the next element of a linked list, one normally does this:

  ptr = ptr->next;

assuming a structure like this:

  struct llist {
    struc llist *next;
    /* your specific elements */
  };

  struct llist *ptr;

:)
:) Maybe I've missed something glaringly obvious.
:) Anyway does anyone have any thoughts, and also can anyone think of a better
:) way to do a state machine.
:) In the past I've used switch and case,  and also pointers to functions with
:) each function being a state and it setting the next state to call.
:)
:) This time I'd like something a little more abstract and configurable so that
:) I can change the state machine depending on the mode I'm in.
:)
:) I'm using atmega 128 and gcc 3.2

Hope that helps.

Ted Roth

avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]