开发者

what does "layout-compatible with C" mean?

开发者 https://www.devze.com 2023-02-17 10:16 出处:网络
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, &ve

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号