warning: implicit declaration of function

前端 未结 7 932
旧时难觅i
旧时难觅i 2020-11-22 02:19

My compiler (GCC) is giving me the warning:

warning: implicit declaration of function

Please help me understand why is it coming

7条回答
  •  情书的邮戳
    2020-11-22 03:06

    You are using a function for which the compiler has not seen a declaration ("prototype") yet.

    For example:

    int main()
    {
        fun(2, "21"); /* The compiler has not seen the declaration. */       
        return 0;
    }
    
    int fun(int x, char *p)
    {
        /* ... */
    }
    

    You need to declare your function before main, like this, either directly or in a header:

    int fun(int x, char *p);
    

提交回复
热议问题