Storage Classes

Associating identifiers with objects requires each identifier to have at least two attributes: storage class and type (sometimes referred to as data type). The mikroC PRO for PIC32 compiler deduces these attributes from implicit or explicit declarations in the source code.

A storage class dictates the location (data segment, register, heap, or stack) of object and its duration or lifetime (the entire running time of the program, or during execution of some blocks of code). A storage class can be established by the syntax of a declaration, by its placement in the source code, or by both of these factors:

storage-class type identifier

The storage class specifiers in the mikroC PRO for PIC32 are:

Auto

The auto storage-class specifier declares an automatic variable (a variable with a local lifetime). An auto variable is visible only within the block in which it is declared.
The auto storage-class specifier can only be applied to names of variables declared in a block or tonames of function parameters.
However, these names have automatic storage by default. Therefore the auto storage class specifier is usually redundant in a data declaration.

Register

The register storage-class specifier is used to define local variables that should be stored in a register instead of RAM. At the moment this modifier has no special meaning in mikroC PRO for PIC32.
mikroC PRO for PIC32 simply ignores requests for register allocation.

Static

The static storage class specifier lets you define variables or functions with internal linkage, which means that each instance of a particular identifier represents the same variable or function within one file only.
In addition, variables declared static have static storage duration, which means that memory for these variables is allocated when the program begins running and is freed when the program terminates.
Static storage duration for a variable is different from file or global scope. A variable can have static duration, but local scope.

Extern

The extern storage class specifier lets you declare objects that can be used in several source files. An extern declaration makes a described variable usable by the succeeding part of the current source file.
This declaration does not replace the definition. It is used to describe a variable that is externally defined. An extern declaration can appear outside a function or at the beginning of a block.
If the declaration describes a function or appears outside a function and describes an object with external linkage, the keyword extern is optional.
If a declaration for an identifier already exists within the file scope, any extern declaration of the same identifier found within a block refers to the same object.
If no other declaration for the identifier exists within the file scope, the identifier has external linkage.

See Linkage for more information.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code