Why do I get a warning every time I use malloc?

后端 未结 5 760
情话喂你
情话喂你 2020-11-28 06:01

If I use malloc in my code:

int *x = malloc(sizeof(int));

I get this warning from gcc:

new.c:7: w         


        
5条回答
  •  甜味超标
    2020-11-28 06:24

    You need to include the header file that declares the function, for example:

    #include 
    

    If you don't include this header file, the function is not known to the compiler. So it sees it as undeclared.

提交回复
热议问题