expected identifier or '(' before 'for'
/** @file alloc.c */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#define NEW_BLOCK_SIZE 1024
#define ARRAY_SIZE 31
typedef struct _metadata_mem
{
size_t size;
void * addr ;
struct _metadata_mem * next_free ;
struct _metadata_mem * pre_free;
char * unit ;
} metadata_mem;
#define SIZE_OF_MATEDATA sizeof(metadata_mem)
metadata_mem * array_of_block[31] ;
int i;
for(i=0; i<31; i++){
array_of_block[i]=NULL;
}
int index(size_t size){
int count=0;
while((int)size>=2){
size/=2;
count++;
}
return count ;
}
I received the following error and it starts in the for loop:
gcc alloc.c -O3 -Wextra -Wall -Werror -Wno-unused-result
-Wno-unused-parameter -o alloc.so -shared -fPIC
alloc.c:30:2: error: expected identifier or '(' before 'for'
alloc.c:30:12: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '<' token
alloc.c:30:26: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '++' token
alloc.c:35:5: error: conflicting types for 'index'
make: *** [alloc.so] Error 1
I have no idea what's wrong with the for loop. It seems OK. Am I not
supposed to initialized the array_of_block in the global context ?
Thanks a lot.
No comments:
Post a Comment