Code Generation for Constants in Structures and Arrays
The code generator does not recognize constant structure fields or array elements in
the following cases:
Fields or elements are assigned inside control constructs
In the following code, the code generator recognizes that the structure fields
s.a
and s.b
are constants.
If any structure field is assigned inside a
control construct, the code generator does not recognize the constant fields. This
limitation also applies to arrays with constant elements. Consider the following
code:
The code generator does not recognize that s.a
and
s.b
are constant. If variable-sizing is enabled,
y
is treated as a variable-size array. If variable-sizing is
disabled, the code generator reports an error.
Constants are assigned to array elements using non-scalar indexing
In the following code, the code generator recognizes that a(1)
is
constant.
In the following code, because a(1)
is assigned using
non-scalar indexing, the code generator does not recognize that
a(1)
is constant.
A function returns a structure or array that has constant and nonconstant
elements
For an output structure that has both constant and nonconstant fields, the code
generator does not recognize the constant fields. This limitation also applies to
arrays that have constant and nonconstant elements. Consider the following
code:
Because create_structure
returns a structure
s
that has one constant field and one nonconstant field, the
code generator does not recognize that s.a
is constant. The
coder.const
call fails because s.a
is not
constant.