Re: Strange function use
On Thu, 03 Aug 2006 12:17:14 +0200, Christian Christmann
<plfriko@yahoo. dewrote in comp.lang.c:
Part of your confusion is based on a misunderstandin g of this:
int foo(int);
....regardless of the fact that it as at block scope rather than file
scope.
The declaration (not prototype) above declares foo to be a function
that returns an int and accepts an unspecified but fixed number and
type of arguments.
It most specifically is NOT a prototype for a function that takes no
arguments. In another language that stole much of an earlier version
of C, these two declarations are equivalent:
int foo();
int foo(void);
....that is not the case in real, genuine, C.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
On Thu, 03 Aug 2006 12:17:14 +0200, Christian Christmann
<plfriko@yahoo. dewrote in comp.lang.c:
On Thu, 03 Aug 2006 02:51:39 -0700, lovecreatesbeau ty wrote:
>
Christian Christmann wrote:
int a, b, foo( int );
int foo( ); /*int foo( int );*/
It's not a function use/call, foo() occurs inside a declaration. It's a
function prototype declaration.
>
But it's a declaration that deviates from the declaration
given in line 1. There's no function "foo" defined without
any parameters, so why is the declaration from line 8
accepted by a compiler?
>
Christian Christmann wrote:
1 int foo( int f )
2 {
3 return f;
4 }
5
6 int main( void )
7 {
8 int a, b, foo();
2 {
3 return f;
4 }
5
6 int main( void )
7 {
8 int a, b, foo();
9 a = 10;
10 b = foo( a );
11
12 return 0;
13 }
>
I don't understand the use of function "foo" in line 8.
What's it's purpose? It's called without assigning it's
return value to any variable. Furthermore, I wonder
return value to any variable. Furthermore, I wonder
why this function use is allowed at all. According to
the function prototype "foo" expects an integer argument
that is in line 8 not given. Compiling the code with
"gcc -Wall -ansi" does not issue any warning/errors.
10 b = foo( a );
11
12 return 0;
13 }
>
I don't understand the use of function "foo" in line 8.
What's it's purpose? It's called without assigning it's
return value to any variable. Furthermore, I wonder
return value to any variable. Furthermore, I wonder
why this function use is allowed at all. According to
the function prototype "foo" expects an integer argument
that is in line 8 not given. Compiling the code with
"gcc -Wall -ansi" does not issue any warning/errors.
It's not a function use/call, foo() occurs inside a declaration. It's a
function prototype declaration.
But it's a declaration that deviates from the declaration
given in line 1. There's no function "foo" defined without
any parameters, so why is the declaration from line 8
accepted by a compiler?
int foo(int);
....regardless of the fact that it as at block scope rather than file
scope.
The declaration (not prototype) above declares foo to be a function
that returns an int and accepts an unspecified but fixed number and
type of arguments.
It most specifically is NOT a prototype for a function that takes no
arguments. In another language that stole much of an earlier version
of C, these two declarations are equivalent:
int foo();
int foo(void);
....that is not the case in real, genuine, C.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
Comment