2011-05-06 5 views
1

이 오류가 발생합니다. 도와주세요!포인터 및 연결된 목록 제거 기능이있는 호환되지 않는 유형

3.C : 함수 메인 :

3.C : 92 : 오류 : 호환 타입

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

typedef struct pr_struct{ 
     int owner; 
     int burst_time; 
     struct pr_struct *next_prcmd; 
} prcmd_t; 
static prcmd_t *pr_head = NULL; 
static prcmd_t *pr_tail = NULL; 
static int pending_request = 0; 
static pthread_mutex_t prmutex = PTHREAD_MUTEX_INITIALIZER; 


int add_queue(prcmd_t *node) 
{  pthread_mutex_lock(&prmutex); 
     //code 
     prcmd_t *curNode = pr_head; 
     if(pr_head == NULL) { pr_head = node; return;} 
     while(curNode->next_prcmd) 
     { 
       curNode = curNode->next_prcmd; 
     } 
     curNode->next_prcmd = node; 

     // 
     pending_request++; 
     pthread_mutex_unlock(&prmutex); 
     return(0); 
} 

**//inprogress 
int remove_queue(prcmd_t **node) 
{ 
    printf("prenull"); 
    pthread_mutex_lock(&prmutex); 
    prcmd_t *tempNode; 
    if(node == NULL) 
    { 
     //your code 
     printf("Queue is empty"); 
     // 
     pthread_mutex_unlock(&prmutex); 
     return(-1); 
    } 
    else 
    { 
    printf("in else"); 
     //your code 
     tempNode =(*node)->next_prcmd; 
     free(node); 
     // 
     pending_request--; 
     pthread_mutex_unlock(&prmutex); 
     return(0); 
    } 
} 
//end progress** 


int main() 
{ 

    if (pr_head == NULL) 
    { 

     printf("List is empty!\n\n"); 
    } 

    int i=0; 
    int length = 4; 
    prcmd_t *pr[length]; 
    for(i =0;i<length;i++) 
    { 
     pr[i] = (prcmd_t*)malloc(sizeof(prcmd_t)); 
     pr[i]->owner = i+1; 
     pr[i]->burst_time = i + 2; 
     add_queue(pr[i]); 
    } 


    prcmd_t *curNode = pr_head; 

    while(curNode) 
    { 
     printf("%i %i\n", curNode->owner,curNode->burst_time); 
     curNode = curNode->next_prcmd; 
    } 
**//something is messed up here i think. 
    curNode = *pr_head; 
    remove_queue(&curNode); 
//** 

    while(curNode) 
    { 
     printf("%i %i\n", curNode->owner,curNode->burst_time); 
     curNode = curNode->next_prcmd; 
    } 
} 

답변

1

curNode 유형 prcmd_t *이다 prcmd_t (유형에서 * 포인터 구조체 prcmd_t를 입력 지정할 때 prcmd_t) 및 pr_headprcmd_t *이기 때문에 동일한 참조 수준에 있지만 pr_head (prcmd_t 유형)의 값을 curNode (유형은 prcmd_t *)으로 지정하려고합니다. 비 호환성.

그것은 당신이하려고하지만, 올바른 구문 중 하나

curNode = pr_head; 

또는

memcpy(curNode, pr_head, sizeof(prcmd_t)); 
무엇인지 나에게 분명하지 않다
관련 문제