ABL electronic PIC16 Personal Computer User Manual


 
Functions are central to C programming. Functions are usually defined as subpro-
grams which return a value based on a number of input parameters. Return value
of a function can be used in expressions – technically, function call is considered
an operator like any other.
C allows a function to create results other than its return value, referred to as side
effects. Often, function return value is not used at all, depending on the side
effects. These functions are equivalent to procedures of other programming lan-
guages, such as Pascal. C does not distinguish between procedure and function –
functions play both roles.
Each program must have a single external function named main marking the entry
point of the program. Functions are usually declared as prototypes in standard or
user-supplied header files, or within program files. Functions have external linkage
by default and are normally accessible from any file in the program. This can be
restricted by using the static storage class specifier in function declaration (see
Storage Classes and Linkage).
Note: Check the PIC Specifics for more info on functions’ limitations on PIC
micros.
Function Declaration
Functions are declared in your source files or made available by linking precom-
piled libraries. Declaration syntax of a function is:
type function_name
(
parameter-declarator-list
);
The
function_name
must be a valid identifier. This name is used to call the
function; see Function Calls for more information. The
type
represents the type
of function result, and can be any standard or user-defined type. For functions that
do not return value, you should use
void type. The
type
can be omitted in global
function declarations, and function will assume int type by default.
Function
type
can also be a pointer. For example, float* means that the func-
tion result is a pointer to float. Generic pointer, void* is also allowed. Function
cannot return array or another function.
MikroElektronika:
Development
tools
-
Books
-
Compilers
95
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
FUNCTIONS