Datasheet

Initialization
The initial value of a declared object can be set at the time of declaration (initializa-
tion). A part of the declaration which specifies the initialization is called initializer.
Initializers for globals and
static objects must be constants or constant expres-
sions. The initializer for an automatic object can be any legal expression that eval-
uates to an assignment-compatible value for the type of the variable involved.
Scalar types are initialized with a single expression, which can optionally be
enclosed in braces. The initial value of an object is that of the expression; the same
constraints for type and conversions as for simple assignments are applied to initial-
izations too.
For example:
int i = 1;
char *s = "hello";
struct complex c = {0.1, -0.2};
// where 'complex' is a structure (float, float)
For structures or unions with automatic storage duration, the initializer must be one
of the following:
- An initializer list.
- A single expression with compatible union or structure type. In this case,
the initial value of the object is that of the expression.
For example:
struct dot {int x; int y; } m = {30, 40};
For more information, refer to Structures and Unions.
Also, you can initialize arrays of character type with a literal string, optionally
enclosed in braces. Each character in the string, including the null terminator, initial-
izes successive elements in the array. For more information, refer to Arrays.
Automatic Initialization
The mikroC PRO for AVR does not provide automatic initialization for objects. Uninitial-
ized globals and objects with static duration will take random values from memory.
186
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5