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: Jeff Rose
Subject: Re: [avr-gcc-list] Linked lists.
Date: Mon, 9 Dec 2002 11:33:04 -0700 (MST)

Without looking at the code it's hard to say exactly what your problem is,
but here are some ideas...  First, pointer++ will increment a pointer by
the number of bytes that are allocated for that type of struct.  In an
array of structs, this would work fine, but depending on your linked list
the structs might not be in contiguous memory locations.  You need to look
at the *next pointer to go to the next element.  The other possible
problem is that you are using the wrong pointer type.  You have to use a
pointer that is declared as a pointer to the type of struct you are using.
(Although you could probably typecast also...)
        As for state machines, I have seen them using tree structures
of nodes like you are using, or using some type of jump table where you
have the addrs stored in a permanent array and you use indices into the
array.

Good Luck,
Jeff

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.
>
> 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]