2013-09-27 75 views
0

我對C非常陌生,並且無法通過關於此編譯錯誤的一些過去線程來解決我的問題。gcc錯誤:期望'=',',','ASM'或'__attribute__'在'出列'之前

這是我的代碼:

#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。

+1

要具體。你得到什麼錯誤等? – Drew

+0

錯誤出現在我的標題中:期望'=',',','ASM'或'__attribute__'在'出列'之前。 gcc告訴我錯誤發生在頂層。 – bogdan

回答

0

更新您的結構

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);

+0

感謝您的回覆。我確實嘗試過,但「出列」之前的「expected」=',',','ASM'或'__attribute__'「錯誤仍然存​​在。 – bogdan

+0

@ user2821811結構標籤PCB由您使用兩次。檢查我更新的答案。 – Jeyaram

+0

仍然沒有運氣。我不認爲結構是錯的,錯誤引用了我的「出隊」函數。 – bogdan

相關問題