The floating-point 0.5
prevents the array size from being considered an integer constant expression. You can divide by the integer 2
instead, changing 0.5*(LxIni+LxIni)
to (LxIni+LxIni)/2
. You could also change it to LxIni
, which should be mathematically equivalent if there is no overflow or wrapping. (Is that a typo, did you mean to add two different things rather than adding something to itself and then dividing by two, which seems pointless?)
This is intentional in the design of C; the size of a static-duration array must be an integer constant expression, which cannot use floating-point operands in arithmetic (except that a C implementation could choose to allow them).
C 2018 6.7.6.2 2 says objects with static storage duration (which includes arrays defined outside functions) must not have a variable length array type:
… If an identifier is declared to be an object with static or thread storage duration, it shall not have a variable length array type.
6.7.6.2 4 says if the size is not an integer constant expression, the array is a variable length array type:
… If the size is an integer constant expression and the element type has a known constant size, the array type is not a variable length array type; otherwise, the array type is a variable length array type…
6.6 6 restricts the use of floating-point constants in integer constant expressions [bold added]:
… An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof
expressions whose results are integer constants, _Alignof
expressions, and floating constants that are the immediate operands of casts…
A C implementation could choose to support floating-point arithmetic in integer constant expressions, as 6.6 10 says:
An implementation may accept other forms of constant expressions.
However, your implementation apparently choose not to do so.