Flexible array members are an odd feature of C that is intended to capture the pattern of a variable-length structure consisting of a header followed by an array of some element type. It’s a very specific pattern where the last element of a structure can be an array with no size information, like this:

struct Path {
unsigned num_points;
_Bool isClosed;
struct Point points[];
};

struct Point {
double x, y;
};

Flexible array members are not technically part of C++, but are available as an extension in most every C++ compiler because they’re common enough in C that you need them for compatibility with some C libraries.

I recently ran across some Swift code that was using a C API based on flexible array members. The c…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help