C function with no parameters behavior

前端 未结 2 1961
时光说笑
时光说笑 2020-11-29 05:46

Can somebody explain to me why the following code does compile without a warning or error?

I would expect the compiler to warn me that the function no_args

2条回答
  •  借酒劲吻你
    2020-11-29 06:17

    When you declare a function with an empty argument list, you invoke K&R (pre-prototype) semantics and nothing is assumed about the parameter list; this is so that pre-ANSI C code will still compile. If you want a prototyped function with an empty parameter list, use (void) instead of ().

提交回复
热议问题