Hi guys
I have a small problem. It could be not enough information to obtain the right answer but I will try. So I have a problem regarding liked lists. It works perfectly fine when is compliled under Windows using Dev-C++ compileer. But when I try to complile under Unix system using gcc compiler it gives me bunch of errors. It is C program. I provide you than one particular fuction, so it will be easy to locate the problem. In that case when I compile it says that tehre is 'parse error before struct'. When I will comment if statement, the one just before the struct it will work, but I need that statement. Why I receive the parse error, how may I fix it.
Is it a C syntax?
Thanks
int allocate_mem(int size)
{
// check ranges
if (size < 0 || size > 10000)
return -1;
struct free_block *best_fit_block = NULL;
struct free_block *prev_to_best_fit_block = NULL;
struct free_block *current_block = memory->head;
struct free_block *previous_block = NULL;
// system is out of memory
if (current_block == NULL) return -1;
// otherwise look over free blocks to find first, which fits
while (current_block != NULL)
{
if (current_block->size >= size)
break;
else
{
previous_block = current_block;
current_block = current_block->next;
}
}
if (current_block == NULL)
{
// system is out of blocks, big enough
return -1;
}
prev_to_best_fit_block = previous_block;
best_fit_block = current_block;
previous_block = current_block;
current_block = current_block->next;
// look over rest and try to find the one, which fits better
while (current_block != NULL && best_fit_block->size != size)
{
if (current_block->size >= size && current_block->size < best_fit_block->size)
{
prev_to_best_fit_block = previous_block;
best_fit_block = current_block;
}
previous_block = current_block;
current_block = current_block->next;
}