https://wiki.freepascal.org/Flexible_Array_Member
Nicely done.
Just a few comments on the contents.
It is correct that flexible array members, i.e,
array[], are not part of the C++ standard but, MS C++ supports it and, I believe but I am not sure, g++ does as well.
Both of them support a construct that is mostly equivalent, that is,
array[0].
The older api struct definitions used
array[1] (or
ANYSIZE_ARRAY to make it clearer that it wasn't really just a single byte array.) MS used
array[0] in a _very small_ number of struct definitions. Currently MS seems to favor
array[] (the impression I get is that for new variable length structs,
array[] is what they are consistently using.)
More precisely, a quick parse of a fairly small but representative subset of the Windows API produced the following:
a. array[ANYSIZE_ARRAY] : 69 occurrences, all of them in structs that have existed a very long time.b. array[0] : 2 occurrences, hard to see a timing pattern in such a rather small sample.c. array[] : 7 occurrences, all seven are fairly recent struct definitions, leading to the impression that is what MS is favoring since among the recent structs neither 0 nor ANYSIZE_ARRAY seems to be used. while
array[] is somewhat rare right now, it might become more common as the number of new variable length structs increases.
The other comment is, I believe it would be useful to include Marco's implementation of flexible array member in Pascal, that is::
FlexRec = record
a : DWORD;
b : DWORD;
c : array[0..0] of record end; { cannot specify a type }
end;
and document that this solution will require defining a typed pointer as the address of "c" in order to access the elements in the array.
Also associated with how the array elements are accessed, I believe it would be good to mention that when a function or property is used to define/access the array "c", it is no longer possible to take the address of an array element (this can make the construction unusable if the original C code uses pointers to access the array elements, a rather common practice in C.)