5.7.3. Function Prototypes

A function prototype is a function heading followed by a semicolon instead of by a body. It indicates that a function with this heading will be defined somewhere, and allows your program to use that function without the need for the body to have been supplied. For example, prototypes

  int larger(int x, int y);
  void printHeading();
indicate that functions larger and printHeading will be defined somewhere; their definitions should start with the same heading.

Of course, you will need to ensure that the function is defined, with a body, somewhere. But the definition can be in any module that is linked with your program.


Omitting parameter names

All that a function prototype really needs are the types. The parameter names are ignored. So you can write

  int largest(int, int);
where the names of the parameters have been omitted and only the types are shown. In practice, the names are typically shown because they are helpful to someone reading the prototypes.

If you provide a contract with a function prototype, be sure to include the parameter names. Otherwise, you have no way of referring to them.