Home Segments Index Top Previous Next

248: Mainline

You might think that the function prototype for a function that expects no arguments would look like this model:

return data type function name ( ) 

Alas, the use of a function prototype with no type specifiers is taken to mean that the C compiler should not check argument types or even the number of arguments appearing in function calls. Although such a function prototype is often used for functions that expect no arguments, such a function specification should be reserved, as described in the hardcopy version of this book, for functions that accept a variable number of arguments.

A clearer and safer way to specify a function prototype for a function that expects no arguments is to include only the special symbol void in the place normally reserved for parameter data types:

return data type function name (void) 

By using such a specification, you tell the C compiler to complain if the function ever appears with one or more arguments. Nevertheless, many programmers sacrifice this benefit, using a function specification with no type specifiers, despite the inherent ambiguity.