Function definitions
A function definition
includes the body of the function after
the declaration of the function.
As with declarations, a function may
be defined as a function prototype definition
or defined in the old style.
The function prototype style includes
type declarations for each parameter
in the parameter list.
This example shows how main would be defined in each style:
/* Function Prototype Style */ /* Old Style */
int int
main(int argc, char *argv[]) main(argc, argv)
{ int argc;
... char *argv[];
} {
...
}
Some important rules that govern function definitions:
-
Function definitions can include the
inline
function specifier. This serves as a hint to the compiler
that it might want to replace calls to this function with
an in-line replacement (with identical semantics).
An inline function cannot contain a definition of a modifiable object
with static storage duration, nor can it refer to an identifier with
internal linkage.
NOTE:
No inlining will occur unless the -O option of
cc(CP)
is specified.
-
An old style definition names its parameters in an identifier list,
and their declarations appear between the function declarator
and the ``{'' that begins the function body.
-
Under the old style, if the type declaration
for a parameter was absent, the type defaulted to int.
In the new style, all parameters in the
parameter list must be type-specified and named.
The exception to this rule is the use of ellipsis,
explained in
``Function declarators''
-
A function definition serves as a declaration.
-
Incomplete types are not allowed in the
parameter list or as the return type of a function definition.
They are allowed in other function
declarations.
Next topic:
Conversions and expressions
Previous topic:
Function declarators
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005