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

后端 未结 2 1074
忘了有多久
忘了有多久 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:57

    Because of backward compatibility, a declaration like

    void foo();
    

    doesn't declare a function that takes no argument, it declares a function which takes an unknown number of arguments of unknown type.

    That means both your calls are correct, and the compiler can't really warn you about it.

    The other problematic thing is that the declaration in the source file actually matches the declaration in the header file, it just makes it more precise. Therefore you will not get a warning or error there either.

提交回复
热议问题