简体   繁体   English

“布局与C兼容”是什么意思?

[英]what does “layout-compatible with C” mean?

It is said that stl vector is "layout-compatible with C". 据说stl向量是“与C布局兼容”。 Where can I find the definition of "layout-compatible with C"? 我在哪里可以找到“布局与C兼容”的定义?

这意味着,只要向量不为空, &vector.front()将为您提供指向连续对象数组的指针,这些对象可以传递给期望此类数组的C API。

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. 这意味着向量的内容将以与它们在相同类型的C数组中相同的方式布局在内存中。 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. 这意味着如果你有一个期望接收指向某种类型数组的指针的C函数,你可以使用一个向量并将该指针传递给向量的第一个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM