Re: Strange function use



spibou@xxxxxxxxx wrote:
pemo wrote:

Christian Christmann wrote:
Hi,

in a benchmark I've found an uncommon use of a function.
This is the simplified form:

1 int foo( int f )
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
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.

Could you shed some light on that.

It's not a /call/ but a declaration - it's say that foo is a function
returning an int. I believe it's also /saying/ that foo takes an
unknown number/type of args - however, as foo's definition is in
scope, the compiler already knows about it ... thus the declaration
in line 8 isn't necessary.

What are the semantics of declaring a function inside
another function ?

A declaration of a function is just a /prototype/ - ok?


--
==============
Not a pedant
==============


.



Relevant Pages

  • Re: Question regarding prototypes for 0-ary functions.
    ... int fooint x; ... extern int foo(int, ... ... extern int foo(); is not a valid declaration, ... The definition of foo says it takes one parameter, while the declaration ...
    (comp.lang.c)
  • Re: undefined reference to "..."
    ... compiler has a declaration of the function, ... extern int foo(int); ... Declarations appearing in the header files have ...
    (comp.lang.c)
  • Re: [C] strcat() question (ongoing)
    ... > At the machine level, yes, basically (depending on your definition ... We can only "PUT" data in / or assign data to variables such as an int or ... foo is an object? ... > house and look on the microwave. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Strange function use
    ... int a, b, foo; ... int a, b, foo(int); ... the function prototype "foo" expects an integer argument ... foooccurs inside a declaration. ...
    (comp.lang.c)
  • Re: call of variadic function
    ... arguments that should be passed to this function are of type int. ... You call foo with more arguments than are ... which is the standard way to access arguments of a variadic function ... Here the else clause of my sentence specifies one of the numerous non- ...
    (comp.lang.c)