[Top][All Lists]

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

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

From: Lorne Gutz
Subject: Re: [avr-gcc-list] Linked lists.
Date: Mon, 16 Dec 2002 13:42:17 -0500

There is always more than one way to skin a cat.   Here is 
one example that has worked find for me.

struct    linked_list 
        put in your elements of your structure here
        struct linked_list *NEXT;
        struct linked_list *PREV;

typedef struct linked_list  LINKED_LIST;

Then you create a function that dinamically allocates memory for
a link and returns a pointer to it.  This function should also put 
the pointers NEXT and PREV in as well.  Then if you have a
local variable that is defined as a LINKED_LIST pointer you 
can move up one be  ptr = ptr->NEXT or back with
ptr = ptr->PREV;


On Monday 09 December 2002 11:57, 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.
> 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
> Thanks.
> Dan.
> avr-gcc-list at http://avr1.org

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

reply via email to

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