so I haven't used pointers to this extent for a few years so I'm a little rusty.
I'll give a quick explanation on what the code is supposed to do, but from looking at my output I am messing up pointer arithmetic somewhere along the lines. I'm pretty sure it's a syntax error with pointers somewhere along the lines, so try to spot the error and if you need more explanation on what the code is doing or if you need more code from my program just let me know.
Here is the linked list struct I'm using:
typedef struct free_list{
struct free_list *next;
struct free_list *previous;
int block_size;
int block_adr;
int adjacent_adr;
}list_node;
Here is the code in the main file that is applicable to the error(I think but if you think you need to see more just let me know)
list_node header_node;
list_node current_node;
//This is the for the first node created
header_node.next = (list_node*) malloc(sizeof(list_node));
header_node.previous = 0;
header_node.block_size = size;
header_node.adjacent_adr = memory - 1;
current_node = header_node;
//this is for all subsequent nodes
current_node.next = NULL;
current_node.previous = 0;
current_node.block_size = size;
current_node.block_adr = -1;
current_node.adjacent_adr = -1;
insert_first(&header_node, ¤t_node);
Finally here is the insert function I'm using(its not a normal insert function, once again the problem is the syntax not the algorithm, but if you need a little insight on what is going on just ask)
void insert_first(list_node *current, list_node *new){
list_node *tmp;
if( (current->adjacent_adr - (current->block_adr + current->block_size)) <
new->block_size )
insert_first( current->next, new );
else{
if(current->next == NULL){
current->next = new;
}else{
tmp = current->next;
current->next = new;
new->next = tmp;
}
new->previous = current;
new->block_adr = current->block_size + current->block_adr;
new->adjacent_adr = current->adjacent_adr;
current->adjacent_adr = new->block_adr;
total_free_space = total_free_space - new->block_size;
free_list_length++;
}
}
This last piece of code is looking to return the size of the biggest space of memory available in the linked list(The list starts automatically with 1024000 made up bytes of memory) The purpose of the code is to add and remove pieces of the linked list with arbitrary amounts of memory, then put the newest node into the first spot it would fit.
int largest_chunk( list_node *current, int largest, int memory ){
if( current->adjacent_adr != memory-1 ){
if( (current->adjacent_adr - (current->block_size + current->block_adr))
> largest )
return( largest_chunk( current->next, (current->adjacent_adr -
(current->block_size +
current->block_adr)), memory));
}else{
printf("got here\n");
return(largest);
}
}
Once again any help will be appreciated, I know you may not fully understand what it is I'm trying to do, but the problem comes from playing with the pointers. Any questions just ask.