It is said that stl vector is "layout-compatible with C". Where can I find the definition of "layout-compatible with C"?
This means that, as long as the vector is not empty, &vector.front()
will give you a pointer to a contiguous array of objects, which could be passed to a C API that expects such an array.
It means that the contents of the vector will be laid out in memory the same way they would be in a C array of the same type. That means that if you have a C function that expects to receive a pointer to an array of some type, you can use a vector and pass the function a pointer to the first element of the vector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With