C function with no parameters behavior
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 ()
.
In C++, void no_args()
declares a function that takes no parameters (and returns nothing).
In C, void no_args()
declares a function that takes an unspecified (but not variable) number of parameters (and returns nothing). So all your calls are valid (according to the prototype) in C.
In C, use void no_args(void)
to declare a function that truly takes no parameters (and returns nothing).