Number of arguments mismatch in function call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have a question with function definition.
Please consider following 3 different forms
of writing a same test example:

1.
static int foo(i, j)
  int i;
  float j;
{
  return i;
}
int main()
{
  return foo(1);    // Passing less arguments
}

2.
static int foo(int, float);
static int foo(i, j)
  int i;
  float j;
{
  return i;
}
int main()
{
  return foo(1);    // Passing less arguments
}
test.c: In function 'main':
test.c:10: error: too few arguments to function 'foo'

3.
static int foo(int i, float j)
{
  return i;
}
int main()
{
  return foo(1);    // Passing less arguments
}


I am using gcc version 4.1.2 to compile all the 3 variations as:
% gcc test.c


The first one compiles fine.
While the 2nd & 3rd give following error:
test.c: In function 'main':
test.c:7: error: too few arguments to function 'foo'

Can someone please explain if this is a bug of gcc
or a desired behavior and why?

-- 
Regards,
Sulabh Nangalia

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux