我有一个函数(在某些库中),其签名是这样的:
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/