4 ms·
VLAs can be declared in a single statement, but they cannot be initialized in C17 (6.7.9): > The type of the entity to be initialized shall be an array of unkn
by LegionMammal978 4y ago
VLAs can be declared in a single statement, but they cannot be initialized in C17 (6.7.9):
> The type of the entity to be initialized shall be an array of unknown size or a complete object type that is not a variable length array type.
Curiously, C23 actually seems to break the O(1) rule, by allowing VLAs to be initialized with an empty initializer:
int arr[n] = {};
GCC generates a memset call (https://godbolt.org/z/5v31bKs5a https://godbolt.org/z/5v31bKs5a) to fill the array with zeros.