Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
226
mikoC PRO for PIC32
MikroElektronika
Type Qualifiers
The type qualifiers 
const 
and 
volatile
 are optional in declarations and do not actually affect the type of declared 
object.
Qualifier const
The 
const
 qualifier is used to indicate that variable value cannot be changed. Its value is set at initialization.
The  mikroC  PRO  for  PIC32  treats  objects  declared  with  the 
const
  qualifier  the  same  as  literals  or  preprocessor 
constants. If the user tries to change an object declared with the 
const
 qualifier compiler will report an error.
For example:
const double PI = 3.14159;
Qualifier volatile
The 
volatile 
qualifier indicates that variable values can be changed both with or without user’s interference in the 
program. The compiler should not optimize such variable.
Typedef Specifier
The 
typedef
 declaration introduces a name that, within its scope, becomes a synonym for the specified type. You can 
use typedef declarations to construct shorter or more meaningful names for types already defined by the language or 
declared by the user. 
Typedef names allow you to encapsulate implementation details that may change. Unlike the 
struct
,
 union
, and
 
enum
 declarations, the 
typedef
 declarations do not introduce new types, but new names for existing types.
The specifier 
typedef
 stands first in the declaration:
typedef <type_definition> synonym;
The 
typedef
 keyword assigns 
synonym
 to 
<type_definition>
. The 
synonym
 needs to be a valid identifier.
A declaration starting with the 
typedef 
specifier does not introduce an object or a function of a given type, but rather 
a new name for a given type. In other words, the
 typedef
 declaration is identical to a “normal” declaration, but instead 
of objects, it declares types. It is a common practice to name custom type identifiers with starting capital letter — this is 
not required by the mikroC PRO for PIC32.