我有一个警告,但我不明白为什么:
void stampaCon(){
pthread_mutex_lock(&mutexCon);
printf("lista dei connesi: \n");
int i;
for(i=0; i<=MAX_CONNECTIONS*8; i++){
if(arrayCon[i]!=NULL){
TipoListaReg *s = NULL;
s = arrayCon[i]; //gives me a warning
printf("utente %s\n", arrayCon[i]->utente);
while(s->next!=NULL){
printf("utente %s\n", s->next->utente);
s=s->next;
}
}
}
pthread_mutex_unlock(&mutexCon);
}
TipoListaReg结构是:
typedef struct NodoListaReg {
char utente[MAX_NAME_LENGTH+1];
int connesso;
ListaPendente *msgs;
struct NodoListaReg *next;
} TipoListaReg;
和arrayReg是一个全局变量,定义为:
TipoListaReg *arrayReg[512];
这是一个结构ListaPendente:
typedef struct pendenti{
char msg[MAX_MSG_SIZE];
char mittente[MAX_NAME_LENGTH+1];
int type;
struct pendenti *next;
}ListaPendente;
警告是:
warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
答案 0 :(得分:2)
在你的问题中没有足够的信息,但是没有警告就编译好了:
typedef struct ListaPendente // made up definition by me as you didn't provide
{ // the definition of ListaPendente
int dummy;
} ListaPendente ;
typedef struct NodoListaReg {
char utente[100]; // MAX_NAME_LENGTH replaced by 100 as it is not relevant
int connesso;
ListaPendente *msgs;
struct NodoListaReg *next;
} TipoListaReg;
TipoListaReg *arrayReg[512];
int main()
{
int i = 0;
TipoListaReg *s = arrayReg[i]; // no warning here
}
然而,代码不会做任何有用的事情