M
Maxim Fomin
I have a question related to empty function parameter list: is it
legal to call function with specific arguments via function pointer to
same type with empty parameter list?
Test example is:
#include <stdio.h>
int (*funcptr)();
int foo(int x)
{
return x;
}
int main()
{
funcptr = foo;
printf("%d\n", funcptr(7));
return 0;
}
Compiler that I use issues warning for funcptr definition ("function
declaration isn’t a prototype") but not for call.
n1570 says in 6.7.6.3-3 that an identifier list in a function
declaration which is not a definition should be empty - as far I
understand the statement, it surprisingly forbids features like void
func(int x);
In.14 it says that empty list for function definition means that the
function has no arguments. I understand that for ex. int main(){...}
and int main(void){...} are the same.
But later it says that code void func(){...} is legal and that is
provides no information about arguments. It also says that this is an
"obsolete" way.
So, I found it unclear:
1) whether each function (non-definition) declaration parameter list
should be empty
2) whether void func(void) and void func() are equal
3) related to what is described code obsolete
4) (most important) are function calls via pointers to function with
empty parameter list with some arguments valid (assuming as in the
example that pointer points to proper function)
Thanks in advance.
legal to call function with specific arguments via function pointer to
same type with empty parameter list?
Test example is:
#include <stdio.h>
int (*funcptr)();
int foo(int x)
{
return x;
}
int main()
{
funcptr = foo;
printf("%d\n", funcptr(7));
return 0;
}
Compiler that I use issues warning for funcptr definition ("function
declaration isn’t a prototype") but not for call.
n1570 says in 6.7.6.3-3 that an identifier list in a function
declaration which is not a definition should be empty - as far I
understand the statement, it surprisingly forbids features like void
func(int x);
In.14 it says that empty list for function definition means that the
function has no arguments. I understand that for ex. int main(){...}
and int main(void){...} are the same.
But later it says that code void func(){...} is legal and that is
provides no information about arguments. It also says that this is an
"obsolete" way.
So, I found it unclear:
1) whether each function (non-definition) declaration parameter list
should be empty
2) whether void func(void) and void func() are equal
3) related to what is described code obsolete
4) (most important) are function calls via pointers to function with
empty parameter list with some arguments valid (assuming as in the
example that pointer points to proper function)
Thanks in advance.