User`s manual

Dynamic C Users Manual digi.com 33
4.10 Functions
The basic unit of a C application program is a function. Most functions accept parameters (a.k.a., argu-
ments) and return results, but there are exceptions. All C functions have a return type that specifies what
kind of result, if any, it returns. A function with a void return type returns no result. If a function is
declared without specifying a return type, the compiler assumes that it is to return an int (integer) value.
A function may call another function, including itself (a recursive call). The main function is called auto-
matically after the program compiles or when the controller powers up. The beginning of the main func-
tion is the entry point to the entire program.
4.11 Prototypes
A function may be declared with a prototype. This is so that:
Functions that have not been compiled may be called.
Recursive functions may be written.
The compiler may perform type-checking on the parameters to make sure that calls to the function
receive arguments of the expected type.
A function prototype describes how to call the function and is nearly identical to the function’s initial code.
It is not necessary to provide parameter names in a prototype, but the parameter type is required, and all
parameters must be included. (If the function accepts a variable number of arguments, as printf does,
use an ellipsis.)
/* This is a function prototype.*/
long tick_count ( char clock_id );
/* This is the function’s definition.*/
long tick_count ( char clock_id ){
...
}
/* This prototype is as good as the one above. */
long tick_count ( char );
/* This is a prototype that uses ellipsis. */
int startup ( device id, ... );