【问题标题】:gcc error: expected '=', ',', 'ASM', or '__attribute__' before 'dequeue'gcc 错误:在 'dequeue' 之前需要 '='、','、'ASM' 或 '__attribute__'
【发布时间】:2013-09-27 03:31:39
【问题描述】:

我对 C 非常陌生,并且无法通过查看此编译错误的一些过去线程来解决我的问题。

这是我的代码:

#include <stdio.h>
#include <stdlib.h>

struct PCB{
/*various data fields within the PCB structure*/
/*in this implementation just ID is included*/
int ID;
struct PCB *next;
struct PCB *prev;
}typedef PCB;


void enqueue(PCB **pntrHN, PCB **pntrTL, PCB passedPCB);
PCB dequeue(PCB **pntrHN, PCB **pntrTL);
void print_queue(PCB **pntrTL);
int size_of_queue(PCB **pntrTL); 
void clear_queue(PCB **pntrHN, PCB **pntrTL); 

int main(int argc, char * argv[])
{
PCB **headOfQueue;
PCB **tailOfQueue;
PCB pcbNode;

headOfQueue = malloc(sizeof(PCB*));
tailOfQueue = malloc(sizeof(PCB*));
*headOfQueue = 0;
*tailOfQueue = 0;
for(i=0; j<100; j++)
{
    PCB temp;
    temp.ID = rand()%30000+20001;
    enqueue(headOfQueue,tailOfQueue,temp);
}

print_queue(tailOfQueue);
int size = size_of_queue(tailOfQueue);
printf("Size of queue: %d\n", size);
clear_queue(headOfQueue, tailOfQueue);
size = size_of_queue(tailOfQueue);
printf("Size of queue now: %d\n", size);
return(0);
}
/*enqueue is here*/
PCB dequeue(PCB **pntrHN, PCB **pntrTL)
{
PCB *tempHead; /*temp var for new head*/
PCB returnVal;

if((*pntrHN)->next !=0){
printf("nodes next is not 0");
exit(0);
}
if(*pntrHN == 0){
printf("dequeued an empty queue");
exit(0);
}
if(*pntrTL == 0){
printf("dequeued empty queue");
printf("head is not zero but tail is");
exit(0);
}
returnVal = **pntrHN; /*get data for return*/

if(*pntrHN == *pntrTL){
*pntrTL = 0;
tempHead = 0;
}else{
tempHead = (*pntrHN)->prev; /*get new head*/
tempHead ->next = 0;
}
free(*pntrHN); /*free old head*/ 
*pntrHN = tempHead; /*set class attribute to new tail*/
return returnVal;
}

void clear_queue(PCB **pntrHN, PCB **pntrTL)
{
PCB holder;
if(*pntrTL != 0){
    while(*pntrHN != 0){
        (*pntrHN)->prev = *pntrHN;
        holder = dequeue(**pntrHN, **pntrTL);
    }
}
}
}

我的语法好吗?我现在真的不知道我哪里错了。我正在通过 ssh 使用 notepad++ 和 gcc。

【问题讨论】:

  • 要具体。您遇到什么错误等?
  • 错误出现在我的标题中:在 'dequeue' 之前需要 '='、','、'ASM' 或 'attribute'。 gcc 告诉我错误发生在顶层。

标签: c gcc struct linked-list queue


【解决方案1】:

更新你的结构为

typedef struct {
   /*various data fields within the PCB structure*/
   /*in this implementation just ID is included*/
   int ID;
   struct PCB *next;
   struct PCB *prev;
}PCB;

1.

In function main:<br/>
undefined reference to enqueue
undefined reference to print_queue
undefined reference to size_of_queue
undefined reference to size_of_queue


2.改变

for(i=0; j<100; j++)

for(j=0; j<100; j++)

并声明j;

按照语法

dequeue(**pntrHN, **pntrTL); 更改为dequeue(pntrHN, pntrTL);

【讨论】:

  • 感谢您的回复。我确实尝试过,但错误“预期 '='、','、'ASM' 或 'attribute' before 'dequeue'”仍然存在。
  • @user2821811 struct tag PCB 被您使用了两次。检查我更新的答案。
  • 还是没有运气。我认为结构没有错,错误引用了我的“dequeue”函数。
  • 是的,我没有包含我的所有代码,因为它无关紧要。因此未定义的引用。而且我的形式参数的语法很好,我打算使用指向指针而不是实际值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-18
相关资源
最近更新 更多