5.7.3. Function Prototypes

A function prototype is a function heading followed by a semicolon. It indicates that a function with this heading will be defined somewhere, and allows your program to use that function even though a full definition of the function has not been seen. 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 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 a person 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.