Initialization of Composite Elements
By default, composite elements used as variables or parameters are initialized in the generated code as follows:
Array
Arrays are initialized in the order of increasing index. See Array with fixed size and Array with variant size for examples.
Matrix
Matrices are generated as one- or two-dimensional arrays in the C code, depending on the Number of dimensions for fixed matrixestarget option. See Matrix with fixed X and Y size and Matrix with variant X and Y size for examples.
Characteristic line/map
The axes of normal characteristic lines/maps are initialized in the order of increasing index. The values of characteristic lines are initialized similar to arrays. The values of characteristic maps are initialized similar to matrices. See Characteristic line and Characteristic map for examples.
The code for these initializations can become very long, especially for arrays and matrices with variant size and a large max. size. This is a challenge for compilers, code comparison tools, etc. In the worst case, the initializations can become so long that the ECCO
Embedded Code Creator and Optimizer aborts with an out-of-memory error.
To solve this problem, ASCETV6.4.10 contains a target option, Generating Sparse Arrays, that optimizes initialization code generation for sparse arrays and matrices of scalar or enumeration type. This option is available for experimental targets (RP targets, PC target) and ASCET‑SE targets (ANSI-C target, EHOOKS target, microcontroller targets).
When Generating Sparse Arrays is activated, you can define a threshold number, which is interpreted as the minimum percentage of 0 values among the init values of all array/matrix elements, or values of a characteristic line/map. Initialization code is generated as follows:
If all array/matrix elements, or all values of a characteristic line/map, are initialized with 0 (false, the enumerator with value 0, 0.0F, 0.0), the following happens:
An array/matrix is initialized as { 0 }.
The values of a characteristic line/map are initialized as { 0 }.
If the threshold value is met, and if the length of the initialization code that omits all elements initialized with 0 and contains designators for all non-zero elements is less than the length of the default initialization code, the following happens:
Only non-zero array/matrix elements, or values of a characteristic line/map, appear in the initialization code. They are initialized with designators that mark their position in the array, matrix, or characteristic line/map: { [0] = 200, [1] = 300 }
- In all other cases, the arrays, matrices, and characteristic lines/maps are initialized with the default initialization.
Note |
|---|
Some compilers cannot process the optimized initialization code generated with activated Generating Sparse Arrays. The information whether or not a particular compiler supports the optimized initialization code is given in the ASCET options window, External Tools\Compiler\<compiler name> node, Supports Generation of Sparse Arrays option. |
See also
Examples: Initialization of Composite Elements