4.65 Flexible array members in C99

In a struct with more than one member, the last member of the struct can have incomplete array type. Such a member is called a flexible array member of the struct.

Note

When a struct has a flexible array member, the entire struct itself has incomplete type.
Flexible array members enable you to mimic dynamic type specification in C in the sense that you can defer the specification of the array size to runtime. For example:
extern const int n;
typedef struct
{
    int len;
    char p[];
} str;
void foo(void)
{
    size_t str_size = sizeof(str);  // equivalent to offsetoff(str, p)
    str *s = malloc(str_size + (sizeof(char) * n));
}
Related concepts
4.59 New language features of C99
4.61 // comments in C99 and C90
4.62 Compound literals in C99
4.63 Designated initializers in C99
4.64 Hexadecimal floating-point numbers in C99
4.66 __func__ predefined identifier in C99
4.67 inline functions in C99
4.68 long long data type in C99 and C90
4.69 Macros with a variable number of arguments in C99
4.70 Mixed declarations and statements in C99
4.71 New block scopes for selection and iteration statements in C99
4.72 _Pragma preprocessing operator in C99
4.73 Restricted pointers in C99
4.75 Complex numbers in C99
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.