mikroC

mikroC - C Compiler for Microchip PIC microcontrollers

making it simple...

Initialization

At the time of declaration, you can set the initial value of a declared object, i.e. initialize it. Part of the declaration which specifies the initialization is called the initializer.

Initializers for globals and static objects must be constants or constant expressions. The initializer for an automatic object can be any legal expression that evaluates 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 the object is that of the expression; the same constraints for type and conversions apply as for simple assignments.

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 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, initializes successive elements in the array. For more information, refer to Arrays.

Automatic Initialization

mikroC does not provide automatic initialization for objects. Uninitialized globals and objects with static duration will take random values from memory.

page

 

94

MikroElektronika: Development tools - Books - Compilers