c指针数组参数

标签 c pointers

我有一个函数(在某些库中),其签名是这样的:

extern LIB3DSAPI void lib3ds_mesh_calculate_face_normals(Lib3dsMesh *mesh, float (*face_normals)[3]);

它在第二个参数中期望什么?

我试过这个:

        float   *norm_verts[3];
        norm_verts=(float(*)[3])malloc(3*sizeof(float[3])*mesh->nfaces);
        lib3ds_mesh_calculate_face_normals(mesh, norm_faces);

在第二行,它说 Expression must be modifiable value 第三行说 argument of type float** is incompatible with parameter of type float(*)[3]

我的直觉是 float* [3] 只是 3 个指针,但为什么 * 是用方括号括起来的?

最佳答案

float (*face_normals)[3] // face_normals is a pointer (to an array of 3 floats)
float *norm_verts[3];    // norm_verts is an array of 3 pointers (to float)

指针不是数组,数组也不是指针。 我建议你阅读 comp.lang.c FAQ , 从第 6 节开始。

关于c指针数组参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13088947/

相关文章:

C String 拆分并打印标记。

c - 对结构体指针数组进行排序

c++ - 为什么 cocos 2d-x v3 在 c++ 中如此频繁地使用指针?

C#:使用指针类型作为字段?

c - 为函数中的结构分配内存

c - 如何将一个函数的结果传递给另一个函数?

c - C语言中这个指向指针的指针语句是什么意思?

将 int 复制到不同的内存位置,接收比预期更多的字节

c - 输入从 A 跳到 B,并在同一行中打印。操作系统C

c - 禁用系统 header 的某些警告