C-不兼容指针警告的初始化



我有警告,但我不明白为什么:

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 %sn", arrayCon[i]->utente);
            while(s->next!=NULL){
                printf("utente %sn", 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]

您的问题中没有足够的信息,但这可以很好地编译,没有警告:

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
}

但是,代码不会做任何有用的

相关内容

  • 没有找到相关文章

最新更新