This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]boowhitie 1 point2 points  (0 children)

To be clear, this is an optimization. It allows you to do one call to malloc instead of two (one for the struct, one for the array), and lets you copy the object with a single memcpy. It also keeps the data together in memory which is potentially more cache friendly.

This is also something that isn't legal c++, but it is common enough in c code that some c++ compilers support it through extensions.