/** @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 ;
}
我收到以下错误,它在 for 循环中开始:
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
我不知道 for 循环有什么问题。好像没问题。我不应该在全局上下文中初始化 array_of_block 吗?
非常感谢。