Eu tenho este código:
#include<stdio.h>
#include<stdlib.h>
typedef struct{
int data;
struct node *next;
} NODE;
NODE *head = NULL;
void display_ll(NODE *head){
if (head == NULL){
printf("\nList is empty");
} else{
for(NODE *curr=head; curr!=NULL; curr=curr->next){
printf("%d ->", curr->data);
}
printf("\b\b ");
}
}
int main(void){
NODE *temp = (NODE *)malloc(sizeof(NODE));
temp->data = 5;
temp->next = NULL;
head = temp;
display_ll(head);
return 0;
}
Na linha 15, onde faço curr=curr->next
o for
loop, estou recebendo um aviso se compilado usando clang, e um erro se compilado usando gcc:
- barulho:
warning: incompatible pointer types assigning to 'NODE *' from 'struct node *' [-Wincompatible-pointer-types]
- gcc:
error: assignment to ‘NODE *’ from incompatible pointer type ‘struct node *’ [-Wincompatible-pointer-types]`
Eu imaginei uma solução alternativa onde escrevemos a estrutura como typedef struct node {...} NODE;
e funciona. Mas eu quero saber se há alguma correção para isso sem essa redefinição de struct.