User`s manual

Dynamic C Users Manual digi.com 37
4.14 Storage Classes
Variable storage can be auto or static. The term “static” means the data occupies a permanent fixed
location for the life of the program. The term “auto” refers to variables that are placed on the system stack
for the life of a function call.The default storage class is auto, but can be changed by using #class
static. The default storage class can be superseded by the use of the keyword auto or static in a
variable declaration.
These terms apply to local variables, that is, variables defined within a function. If a variable does not
belong to a function, it is called a global variable—available anywhere in the program—but there is no
keyword in C to represent this fact. Global variables always have static storage.
The register type is reserved, but is not currently implemented. Dynamic C will change a variable to
be of type auto if register is encountered. Even though the register keyword is not implemented,
it still can not be used as a variable name or other symbol name. Its use will cause unhelpful error mes-
sages from the compiler.
4.15 Pointers
A pointer is a variable that holds the 16-bit logical address of another variable, a structure, or a function.
The indirection operator (*) is used to declare a variable as a pointer. The address operator (&) is used to
set the pointer to the address of a variable.
In this example, the variable ptr_to_i is a pointer to an integer. The statement “j = *ptr_to_i;” refer-
ences the value of the integer by the use of the asterisk. Using correct pointer terminology, the statement
dereferences the pointer ptr_to_i. Then *ptr_to_i and i have identical values.
Note that ptr_to_i and i do not have the same values because ptr_to_i is a pointer and i is an
int. Note also that * has two meanings (not counting its use as a multiplier in others contexts) in a vari-
able declaration such as int *ptr_to_i; the * means that the variable will be a pointer type, and in
an executable statement j = *ptr_to_i; means “the value stored at the address contained in
ptr_to_i.”
Pointers may point to other pointers.
int *ptr_to_i;
int i;
ptr_to_i = &i; // set pointer equal to the address of i
i = 10: // assign a value to i
j = *ptr_to_i; // this sets j equal to the value in i
int *ptr_to_i;
int **ptr_to_ptr_to_i;
int i,j;
ptr_to_i = &i; // Set pointer equal to the address of i
ptr_to_ptr_to_i = &ptr_to_i; // Set a pointer to the pointer
// to the address of i
i = 10; // Assign a value to i
j = **ptr_to_ptr_to_i; // This sets j equal to the value in i.