Flexible array member
C struct data types may end with a flexible array member with no specified size: typedef struct { size_t len; // there must be at least one other data member double arr[]; // the flexible array member must be last // The compiler may reserve extra padding space here, like it can between struct members } DoubleArray; Typically, such structures serve as the header in a larger, variable memory allocation: // see section on size and padding DoubleArray* darray = malloc(sizeof(DoubleArray) + ...[src] * sizeof(double)); darray->len = ...; for (int i = 0; i len; i++) { darray->arr[i] = ...; // transparently uses the right type (double) }[src]
C struct data types may end with a flexible array member with no specified size: typedef struct { size_t len; // there must be at least one other data member double arr[]; // the flexible array member must be last // The compiler may reserve extra padding space here, like it can between struct members } DoubleArray; Typically, such structures serve as the header in a larger, variable memory allocation: // see section on size and padding DoubleArray* darray = malloc(sizeof(DoubleArray) + ...[src] * sizeof(double)); darray->len = ...; for (int i = 0; i len; i++) { darray->arr[i] = ...; // transparently uses the right type (double) }[src]
4 sentences · 4 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Flexible array member." encyclopegia.org, 2026, https://encyclopegia.org/wiki/flexible-array-member. Accessed 25 November 2026.
Chicago
"Flexible array member." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/flexible-array-member.
APA
encyclopegia.org. (2026). Flexible array member. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/flexible-array-member
Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON