Note that there are some explanatory texts on larger screens.

plurals
  1. POwarning incompatible pointer, why this happens?
    text
    copied!<pre><code>#include &lt;stdio.h&gt; typedef int element_type; typedef struct Cell{ element_type e; struct Cell *next; } Cell,*List; Cell *End(List L){ Cell *q = L; while (q-&gt;next != NULL){ q = q-&gt;next; } return q; } void Insert(Cell *p, element_type x){ //Create new Cell Cell *temp = (Cell*) malloc(sizeof(Cell)); if (temp == NULL){ printf("Memory Allocation Failed"); } else{ temp-&gt;e = x; temp-&gt;next = p-&gt;next; p-&gt;next = temp; } } element_type Retrieve(Cell *p){ return p-&gt;e; } int main(){ //Initialize the List; List L = malloc(sizeof(Cell)); L-&gt;e = NULL; L-&gt;next = NULL; element_type x = 10; Insert(L,x); printf("Just retrievd the item %d\n",Retrieve(L)); return 1; } List_pointer.c: In function ‘Insert’: List_pointer.c:19:24: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default] List_pointer.c: In function ‘main’: List_pointer.c:35:12: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default] List_pointer.c:36:8: warning: assignment makes integer from pointer without a cast [enabled by default] </code></pre> <p>Thanks for all your helps, and I for the part with struct now. However, when I tried to use malloc, I got the warnings again on incompatible declaration. I thought malloc returns a generic pointer to NULL, and hence there shouldn't be any issue with casting? I just not sure what I did wrong here. </p> <p>Also for those of you who wonders why I would implement such a weird interface, I was following the interfaces provided by the book "Data Structure and Algorithm" by Aho. The sample codes were given in Pascal, pretty old style. Although I think there are some merits to learn this super old style way of designing data structure.</p> <p><strong>Update:</strong></p> <p>I just forgot to include the stdlib.h header for malloc! Please refer to this link <a href="https://stackoverflow.com/questions/7050798/incompatible-implicit-declaration-of-built-in-function-malloc">incompatible implicit declaration of built-in function ‘malloc’</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload