Call a function without argument, although it needs one [K&R-C]

前端 未结 3 2007
野性不改
野性不改 2021-01-13 13:42

It\'s K&R-C and here is the code: http://v6shell.org/history/if.c

Look at the main-Method. There is this line \"if(exp())\".

But the function exp is decl

3条回答
  •  旧时难觅i
    2021-01-13 14:10

    This is because in c

    The compiler will not be able to perform compile-time checking of argument types and arity when the function is applied to some arguments. This can cause problems

    Calling an undeclared function is poor style in C (See this) and illegal in C++

    for example-

    #include
    
    void f(int x); 
    
    int main()
    {
       f(); /* Poor style in C, invalid in C++*/
       getchar();
       return 0;
    }
    
    void f(int x)
    { 
       printf("%d", x);
    }
    

    This program will work but shouldn't be used.See this Wiki link for more.

提交回复
热议问题