Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
mikroC PRO for PIC32
MikroElektronika
223
Declarations and Declarators
The declaration contains specifier(s) followed by one or more identifiers (declarators). The declaration begins with 
optional storage class specifiers, type specifiers, and other modifiers. The identifiers are separated by commas and the 
list is terminated by a semicolon.
Declarations of variable identifiers have the following pattern:
storage-class
 [type-qualifiertype var1 [=init1], var2 [=init2], ... ;
where 
var1,  var2,...
 are any sequence of distinct identifiers with optional initializers. Each of the variables is 
declared to be of 
type
; if omitted, 
type
 defaults to 
int
. The specifier 
storage-class
 can take the values 
extern, 
static
,
  register
,
 or the default 
auto
. Optional 
type-qualifier
 can take values 
const 
or
  volatile
. For 
more details, refer to Storage Classes and Type Qualifiers.
For example:
/* Create 3 integer variables called x, y, and z
   and initialize x and y to the values 1 and 2, respectively: */
int x = 1, y = 2, z;   // z remains uninitialized
/* Create a floating-point variable q with static modifier,
   and initialize it to 0.25: */
static float q = .25;
These are all defining declarations; storage is allocated and any optional initializers are applied.
Linkage
An executable program is usually created by compiling several independent translation units, then linking the resulting 
object files with preexisting libraries. A term translation unit refers to a source code file together with any included files, 
but without the source lines omitted by conditional preprocessor directives. A problem arises when the same identifier 
is declared in different scopes (for example, in different files), or declared more than once in the same scope.
The linkage is a process that allows each instance of an identifier to be associated correctly with one particular object 
or function. All identifiers have one of two linkage attributes, closely related to their scope: external linkage or internal 
linkage. These attributes are determined by the placement and format of your declarations, together with an explicit (or 
implicit by default) use of the storage class specifier 
static 
or
 extern
.
Each instance of a particular identifier with external linkage represents the same object or function throughout the entire 
set of files and libraries making up the program. Each instance of a particular identifier with internal linkage represents 
the same object or function within one file only.