Good morning coders !,
I stumbled accross an initialization this morning and even though I get it , it's not 100%. I'll simplify it this way:
I have an array declaration:
uint8_t MyArray[MAX_SIZE]
I have a linked list structure:
struct MyLL{
struct MyLL * next;
struct MyLL * previous;
uint16_t whatever;}
and two globals :
MyLL * FirstBlock;
MyLL * LastBlock;
And then using these in an initialization function this way:
void MyInitFunc(void)
{
MyLL * first;
MyLL * last;
uint8_t * mystart;
uint8_t * myend;
FirstBlock = NULL;
LastBlock = NULL;
mystart = &MyArray[0];
myend = &MyArray[MAX_SIZE];
first = (MyLL *) mystart;
last = (MyLL *) myend;
last--;
first-> whatever= init_whatever;
first->next = last;
first-> previous = NULL;
last-> whatever = init_whatever;
last->next = NULL;
last-> previous = first;
FirstBlock = first;
LastBlock =last;
}
Why is that array so useful? Is it a sort of method to save up space for consecutive linked list pointers ?
I could really sue your help because the moment I thought linked lists were clear , this is shaking my confidence...
Thanks in advance,
T