op_vvec_size_get()
摘要
返回给定值向量中的元素数量。
语法
op_vvec_size_get (vector)
| 参数 | 类型 | 说明 |
|---|---|---|
vector |
Vvec_Vector |
目标向量 [该向量是本过程的操作对象,本过程返回该向量中的元素数量。] |
返回类型
int
指定向量的总大小(以元素计)。
示例
/* Determine the size of a vector before applying it to an esys interface. */
op_ima_obj_attr_get (interface_id, "dimension", &interface_dim);
if (op_vvec_size_get (src_vector) == interface_dim)
{
/* apply the vector value. */
op_esys_interface_vector_set (interface_id, op_sim_time (), src_vector, 0);
}
else
{
printf ("Error: interface dimension and vector size do not match.\n");
}
详情
并非所有元素都必须已定义才计入向量大小。值向量的大小等于向量中最后一个元素的索引号加 1。例如下面的向量大小为 6:
vector = {0, 1, 2, 3, 4, 5}
用途
提供一种确定值向量中元素数量的机制。
错误
- 可恢复错误:值向量无效。
参考
- 使用内核过程 op_vvec_from_value() 将值转换为该值的位表示形式
- 使用内核过程 op_vvec_to_value() 将位表示形式转换为值
- 使用内核过程 op_vvec_type_get() 确定向量的数据类型