Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - too few parameters..., too many parameters...

Node:too few parameters..., Previous:different type arg, Up:...undeclared (first use in this function)



too few parameters..., too many parameters...

Consider the following program:

#include <stdio.h>

void tweedledee (int a, int b, int c)
{
}

void tweedledum (int a, int b)
{
}


/* To shorten example, not using argp */
int main()
{

  tweedledee (1, 2);
  tweedledum (1, 2, 3);

  return 0;
}

The tweedledee function takes three parameters, but main passes it two, whereas the tweedledum function takes two parameters, but main passes it three. The result is a pair of straightforward error messages:

params.c: In function `main':
params.c:14: too few arguments to function `tweedledee'
params.c:15: too many arguments to function `tweedledum'

This is one reason for the existence of function prototypes. Before the ANSI Standard, compilers did not complain about this kind of error. If you were working with a library of functions with which you were not familiar, and you passed one the wrong number of parameters, the error was sometimes difficult to track. Contemporary C compilers such as GCC that follow the standard make finding parameter mismatch errors simple.

 
 
  Published under free license. Design by Interspire