2014-11-13 45 views
0

我想通過參數傳遞一個結構,我無法解決我得到的警告。我寫了一小段獨立的代碼,產生了我在更大的一段代碼中發出的警告消息。問題似乎是我的start_thread參數有誤。我該如何解決這些問題?不知道如何解決我得到的警告

這些是我得到的三個警告。裏面的參數列表中聲明

「結構port_t」

它的作用域僅限於此定義或聲明,這可能是 不是你想要的[默認啓用]

傳遞[默認啓用] [默認啓用]

這裏從兼容的指針類型 「start_thread」參數2是代碼

#include <stdio.h> 
#include <stdlib.h> 
#define N 10 

typedef struct { 
    int port[N]; 
    int id; 
} port_t; 


void createPort(port_t *temp, int id) 
{ 

    temp->port[0] = 0; 
    temp->port[1] = 1; 
    temp->port[2] = 2; 
    temp->port[3] = 3; 
    temp->port[4] = 4; 
    temp->port[5] = 5; 
    temp->port[6] = 6; 
    temp->port[7] = 7; 
    temp->port[8] = 8; 
    temp->port[9] = 9; 
    temp->id = id; 

} 


void send(port_t temp) 
{ 

} 

void start_thread(void *function, struct port_t *port) 
{ 
    printf("In main: creating thread\n"); 

} 



int main(void) { 

    port_t id[100]; 

     int x; 
     for(x =0; x < 100; x++) 
     { 
      createPort(&id[x], x); 
     } 

     start_thread(send, &id[0]); 
    puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 
    return EXIT_SUCCESS; 
} 
+0

'port_t'(w/o「struct」)是一個* unnamed *結構的typedef。 'struct port_t'是別的,可能沒有定義。如果你已經完成了'typedef struct port_t {int port [N]; int id; } port_t;'相反,它們是兼容的(因爲你有一個名爲「port_t」的結構以及typedef)。 – Dmitri

回答

2

start_thread定義中取出「struct」。您已經聲明上述port_ttypedef作爲指向指定結構的指針,這就是您似乎要使用的類型。

struct用於定義一個新的結構類型,您已經有了。

相關問題