typedef struct {
int32 length;
- char data[1];
+ char data[FLEXIBLE_ARRAY_MEMBER];
} text;
- Obviously, the data field declared here is not long enough to hold
- all possible strings. Since it's impossible to declare a variable-size
- structure in
C, we rely on the knowledge that the
-
C compiler won't range-check array subscripts. We
- just allocate the necessary amount of space and then access the array as
- if it were declared the right length. (This is a common trick, which
- you can read about in many textbooks about C.)
+ The [FLEXIBLE_ARRAY_MEMBER]> notation means that the actual
+ length of the data part is not specified by this declaration.