C - gcc: no compiler warning with different function-declaration/implementation

后端 未结 2 1071
忘了有多久
忘了有多久 2021-01-24 04:30

I try to figure out why my c-compiler gives me no warning/error with following (simplified) code.

The function-declaration have no parameters while the function-implemen

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-24 04:54

    In C this function declaration

    void foo();
    

    means that there is nothing known about the function parameters in the point of the declaration.

    The types and number of the parameters are deduced from a function call.

    As for your program then this call

    foo();
    

    has undefined behavior because the number of parameters and the number of arguments mismatch.

提交回复
热议问题