[Top][All Lists]

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

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

From: J.C.Wren
Subject: RE: [avr-gcc-list] Linked lists.
Date: Mon, 9 Dec 2002 14:11:27 -0500

        Be aware that using malloc() in an embedded system is generally 
a Bad Idea.  It can lead to fragmenting where you actually have sufficient
free memory available, but no large enough chucks.  Most embedded systems
are best served by either mallocing one time up front, or use static


-----Original Message-----
From: address@hidden [mailto:address@hidden
Behalf Of Theodore A. Roth
Sent: Monday, December 09, 2002 13:33
To: Daniel Williamson
Cc: address@hidden
Subject: Re: [avr-gcc-list] Linked lists.

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
:) However If I increment the pointer as in pointer++; Then I start going
:) track.  I was rather hoping that incrementing the pointer in this way
:) 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
:) way to do a state machine.
:) In the past I've used switch and case,  and also pointers to functions
:) 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
:) 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

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

reply via email to

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