When I try to compile this small snippet of code I get the following errors:
./main.c:25:8: error: incomplete definition of type 'struct ElementoDiLista'
lista->info=10;
~~~~~^
./main.c:12:16: note: forward declaration of 'struct ElementoDiLista'
typedef struct ElementoDiLista* ListaDiElementi;
advice please ....
the code:
#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
struct elemento
{
int info;
struct elemento* next;
};
typedef struct elemento ElementoDiLista;
typedef struct ElementoDiLista* ListaDiElementi;
int main(void) {
ElementoDiLista elem;
elem.info=10;
elem.next=NULL;
ListaDiElementi lista;
lista=malloc(sizeof(ElementoDiLista));
lista->info=10;
return 0;
}
I expect that my code works since come from a book.
You do not have complete type
struct ElementoDiLista. You have complete typestruct elementoand its aliasElementoDiLista.So instead of this typedef definition
you have to write
The compiler issues an error because in this typedef definition
you introduced a new type specifier
struct ElementoDiListathat is an incomplete type and has nothing common withstruct elementonor with its aliasElementoDiLista.