Skip to content

Harmonisation needed btw 6.2.3.0 and C.2.1

General Information

Mantis ID/URL: CR8217
Clauses: 6.2.3.0 and C.2.1
Affiliation: Gusztáv Adamis Ericsson

Summary

lengthof does not count last, but not initialized elements in 6.2.3.0 (Records and sets of single types/General) and C.2.1 (Length of strings and lists)

Description

In Example 2 of 6.2.3.0 says that this array has 3 elements

EXAMPLE 2:

    var MyRecordOfType v_myVariable := {
        [0] := '111'B,
        [1] := '101'B,
        [2] := -
    }

    v_myVariable := { '10111'B, -, - };
    // after this, v_myVariable contains:
    // { '10111'B, '101'B /* unchanged */, <undefined> /* unchanged */ }

while the definition of the lengthof does not count this last, existing, but not initialized element. It is emphasized at the end of Example 1 of C.2.1.

    // Given
    type record length(0..10) of integer MyList;
    var MyList v_myListVar := { 0, 1, -, 2, - };

    lengthof(v_myListVar);
    // returns 4 without respect to the fact, that the element v_myListVar[2] is not initialized

This is according to the specification of lengthof, but normally we would wait 5 in this situation (as is suggested in 6.2.3.0.)

Edited by Matthias Simon