invalid conversion from 'void*' to 'node*' [-fpermissive]

前端 未结 3 674
说谎
说谎 2020-12-11 04:24

I have a C program that produces an error:

invalid conversion from \'void*\' to \'node*\' [-fpermissive]

Here\'s my code:

         


        
3条回答
  •  情深已故
    2020-12-11 04:58

    You're having this warning/error because you are using malloc (which returns a void*)to initialize a structure of type node* without doing an explicit cast.

    To get rid of this error you could change your code this way :

    head = (struct node *)malloc(sizeof(struct node));
    

    or you could as well add the "-fpermissive" flag to your compiler which will then ignore these errors.

    EDIT: But yeah, i didn't think about the fact that this should not happen in a C compiler anyways

提交回复
热议问题