错误:C宏中')'标记之前的预期语句

迈克尔·亚当
#define ALIGNMENT 8

#define CHUNK_SIZE (1<<12) //Extend heap by this amount (bytes)
#define WSIZE 4
#define DSIZE 8
#define MIN_BLOCK_SIZE (4*WSIZE) //Should it require at least 1 word of payload?

#define MAX(x,y) ((x) > (y) ? (x) : (y))

//Pack a size and allocated bit into a word
//#define PACK(size, alloc) ((size << 1 ) | (alloc))

//Read and write a word at address p
#define GET(p) (*(unsigned int*)(p))
#define PUT(p,val) (*(unsigned int *)(p) = (val))

//Read the size and allocated fields from address p
#define GET_SIZE(hp) (GET(hp)) //alli has doubts
//#define GET_ALLOC(hp) (GET(hp) & 0x1) 
//Get next and prev block pointers from a block
#define GET_NEXT(hp) ((char*)(hp)+2*WSIZE)
#define GET_PREV(hp) ((char*)(hp)+1*WSIZE)

//Given block ptr bp, compute address of its header and footer
//Should we ever reference a block ptr in an explicit list?
#define HDRP(bp) ((char*)(bp) - 3 * WSIZE))
#define FTRP(bp) ((char*)(bp) + GET_SIZE(HDRP(bp)))
#define BP(hp) ((char*)(hp) + (3 * WSIZE))

/* rounds up to the nearest multiple of ALIGNMENT */
#define ALIGN(size) (((size) + (ALIGNMENT-1)) & ~0x7)


#define SIZE_T_SIZE (ALIGN(sizeof(size_t)))

我正进入(状态

错误:C宏中')'标记之前的预期语句

我使用PUT的地方是:

static int extend_heap(size_t words) {
char* hp;
size_t size;

//This returns a ptr to the HEADER of the list allocatable block
void* last_block = find_end_of_free_list();
void* tail = GET_NEXT(last_block);



 //Only allocate an even number of words to maintain alignment
  size = (words % 2) ? (words+1) * WSIZE : words * WSIZE;
  if((long)(hp = mem_sbrk(size)) == -1)
    return -1;

  //Maybe we should make a function (create header/create footer when given an address)
  PUT(hp, size); //Free block header
  PUT(FTRP(BP(hp)), size); //Free block footer

  PUT(GET_PREV(hp), last_block); //Make prev of new block point to end of old list
  PUT(GET_NEXT(hp), tail); //Make next of new block point to tail

  PUT(GET_NEXT(last_block), hp); // Make next of old list point to new list
  return 0;
}

我在PUT上遇到错误。
在extend_heap中,我得到另一个错误:

mm.c:121:3:注意:扩展宏'PUT'PUT(FTRP(BP(hp)),size); //自由块页脚^ mm.c:53:49:错误:')'令牌之前的预期语句#define PUT(p,val)(*(unsigned int *)(p)=(val))

我将代码包含在PUT上方,因为我认为该错误可能是由于其上方的语法引起的。

戈皮

该错误是在行中:

#define HDRP(bp) ((char*)(bp) - 3 * WSIZE))

最后有一个额外的)。应删除其中的一个。由于PUT您正在使用FTRP()宏,并且在此宏之前,HDRP()我们会看到此错误。删除多余的部分)将解决您的问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:在C中的switch语句中定义二维数组时在'{'标记之前的预期表达式

错误:C ++中']'标记之前的预期主表达式

GCC模板:错误:'<'标记之前的预期','或'...'

错误:预期在'='标记之前的':',',',';','}'或'__attribute__'

错误:标头中“ *”标记之前的预期“)”

错误:“{”标记之前的预期表达式

错误:尽管没有包含循环,但预期在'*'标记之前的预期')'

错误:在 struct 中的 '=' 标记之前预期为 ':'、'、'、';'、'}' 或 '__attribute__'

错误:')'标记之前的预期主要表达式(C)

c - 创建 makefile 会导致错误“预期的 ';'、'、' 或 ')' 在 '*' 标记之前”

C ++错误:'('标记之前的预期主表达式

C程序“ {'标记”之前的“预期的”)上的Makefile错误”

C - “错误:预期标识符或 '(' 在 '[' 标记之前”

C ++ 预期 { 标记之前的类名,继承错误

C++ 错误:“{”标记之前的预期类名

C 错误:预期的声明说明符或“*”标记之前的“...”

如何在C ++中修复“错误:')'标记之前的预期主表达式”?

错误:“}”标记之前的预期主表达式

' ' 标记之前的预期主表达式简单错误

无法编译:错误:'('标记之前的预期主表达式

矩阵类:错误:')'标记之前的预期主表达式

错误:“)”标记之前的预期主表达式

模板错误预期在'>'标记之前的主表达式

使用指针调用函数时,在 '&' 标记之前出现错误“预期的 ')'”

C ++预期在'/ ='标记之前的初始化程序

“?” C宏定义中的标记

为什么在以下函数中出现此错误“ pngrutil.c:27:error:在'='标记之前的预期';',','或')'”?

C++ Complie 错误:'+=' 标记之前的预期初始值设定项

C ++错误:“ <'”标记之前的预期构造函数,析构函数或类型转换