Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 2.24 KB

arrays.mkd

File metadata and controls

72 lines (48 loc) · 2.24 KB

Arrays

List of ideas: n2660

  • arrays ...

    • array assignment

    • vectorized operations

    • Lengthof

    • 0 size

    • VLA initialization

    • pointer to VLAs in structs

    • sizeof to VLA in prototype

  • flexible array member

    • sizeof
    • struct return, dereference
    • with struct compatibility, structs with FAM could be incomplete

sizeof

void foo(int i[3])
{
    sizeof(i); // !
    struct { int i; int x[]; } x;
    sizeof(x); // !
}

n2660

Variably Modified Types [C23]

variably modifed types become mandatory in C23

n2907, n2992 (adopted in C23)

Compatibility of Pointers to Arrays with Qualifiers [GCC, Clang, C23]

Multi-dimensional arrays can not be passed to functions expecting const-qualified arrays.

void transpose(int N, int M, double out[M][N], const double in[N][M]);
double a[2][2] = { ... };
double o[2][2];
transpose(2, 2, o, a); // passing 'a' not allowed

The problem is that the rules allowing assignment of pointers to some type to pointers to the qualified types do not work for pointer to arrays because it is only the element type that is qualified and not the array.

Refs.: n1923, n2497, n2607

GCC: Commit

tertiary operator

Related to this are also changes to how the tertiary operator behaves

Fixed: https://godbolt.org/z/6hE3z35fz Clang bug: llvm/llvm-project#54568

VLA Initialization [C23]

VLAs must be initialized in a loop, which is annoying and error prone. As part of general improvements to initialization this was fixed in C23

float a[N] = { };

n2796, n2900