Hi all,
What is the difference between following two function definations?
<1>
void func(void)
{
/* some code */
}
<2>
void func()
{
/* some code */
}
Both define a function returning void, and accepting zero arguments.
They define `func' with different types. The first type is a type
with a prototype, the second type is without a prototype.
If in a function call expression the expression designating the
function has a type without a prototype, and any arguments
are passed, compiler is not required to diagnose an error,
but the behaviour is undefined.
void f();
f(x); //UB, no diagnostic
void f(void);
f(x); //diagnostic
(It's a bit longer story when a function hasn't a prototype, and
has arguments - then the number of arguments and types after
promotion count.)
Why would somebody use 2nd one?
For me it's usually laziness. Maybe there are other reasons,
I don't know.
(Note: there may be important reasons to declare a function
_type_ without a prototype.)