function declaration isn't a prototype

前端 未结 3 1318
渐次进展
渐次进展 2020-12-12 11:14

I have a library I created,

mylib.c:

#include 
int
testlib() {
    printf(\"Hello world\\n\");
    return (0);
}
         


        
3条回答
  •  不知归路
    2020-12-12 12:04

    In C int foo() and int foo(void) are different functions. int foo() accepts an arbitrary number of arguments, while int foo(void) accepts 0 arguments. In C++ they mean the same thing. I suggest that you use void consistently when you mean no arguments.

    If you have a variable a, extern int a; is a way to tell the compiler that a is a symbol that might be present in a different translation unit (C compiler speak for source file), don't resolve it until link time. On the other hand, symbols which are function names are anyway resolved at link time. The meaning of a storage class specifier on a function (extern, static) only affects its visibility and extern is the default, so extern is actually unnecessary.

    I suggest removing the extern, it is extraneous and is usually omitted.

提交回复
热议问题