User manual

Table Of Contents
222
mikoC PRO for PIC32
MikroElektronika
Declarations
A declaration introduces one or several names to a program – it informs the compiler what the name represents, what
its type is, what operations are allowed with it, etc. This section reviews concepts related to declarations: declarations,
denitions, declaration speciers, and initialization.
The range of objects that can be declared includes:
- Variables
- Constants
- Functions
- Types
- Structure, union, and enumeration tags
- Structure members
- Union members
- Arrays of other types
- Statement labels
- Preprocessor macros
Declarations and Denitions
Dening declarations, also known as denitions, beside introducing the name of an object, also establish the creation
(where and when) of an object; that is, the allocation of physical memory and its possible initialization. Referencing
declarations, or just declarations, simply make their identiers and types known to the compiler.
Here is an overview. Declaration is also a denition, except if:
- it declares a function without specifying its body
- it has the extern specier, and has no initializator or body (in case of func.)
- it is the typedef declaration
There can be many referencing declarations for the same identier, especially in a multile program, but only one
dening declaration for that identier is allowed.
For example:
/* Here is a nondening declaration of function max; */
/* it merely informs compiler that max is a function */
int max();
/* Here is a denition of function max: */
int max(int x, int y) {
return (x >= y) ? x : y;
}
/* Denition of variable i: */
int i;
/* Following line is an error, i is already dened! */
int i;