int func(x)
int x;
{
.............
What is this kind of declaration called?
When is it valid/invalid including C or C++, certain standard revisions and compilers?
int func(x)
int x;
{
.............
What is this kind of declaration called?
When is it valid/invalid including C or C++, certain standard revisions and compilers?
K&R style, and I think it's still valid, although discouraged. It probably came from Fortran (where function parameters types are defined inside the function body still in the recent F95)
That is K&R C parameter declaration syntax, which is valid in ANSI C but not in C++.
It's a function prototype. If you didn't do it this way you'd have to write the function out entirely before main, otherwise the compiler wouldn't know what the function was when you used it in main. It's not very descriptive, so it's not used anymore. You'd want to use something like:
int someFunction(int someParamX int someParamY);
It's still valid, but it's pre-ANSI. That's actually where the K&R indent style got its name. The opening bracket is on the line after the function block because this looks weird:
int func(x)
int x; {
...
}
Anyway, this style is not recommended because of a problem with function prototypes.