invalid application of ‘sizeof’ to incomplete type ‘Student’

Asked by JungleRat on 2007-11-08

hello :)

i am writing a code for a linked list of students
when i try to ellocate memory for the struct 'student' i get an error

here is the code:

StudentList* insert(StudentList* sl,char* name,int grade,int ID)
{
 Student* toInsert;
 toInsert=Null;

 if (toInsert = (Student*)malloc(sizeof( Student ))==Null ) // the problem is in this line
 {
 printf("not enough memory \n");
 exit(1);
 }
 else

and this is the error i get :
/home/c_ex_1/src/studentlist.c:268: error: invalid application of ‘sizeof’ to incomplete type ‘Student’

please help
thank you

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu kdevelop Edit question
Assignee:
No assignee Edit question
Solved by:
Vincenzo Consales
Solved:
2007-11-11
Last query:
2007-11-11
Last reply:
2007-11-08

Hi, maybe you get this error because you are trying to set toInsert to 0 or 1 an the compiler tell you that toInsert isn't a boolean.

The correct statement should be:

if ((toInsert = (Student*)malloc(sizeof( Student )))==Null )

JungleRat (yossiturgeman) said : #2

Thanks Vincenzo Consales, that solved my question.