C 编译器警告将结构数组(本身是结构的成员)传递给函数

C 编译器警告将结构数组(本身是结构的成员)传递给函数,c,arrays,pointers,struct,C,Arrays,Pointers,Struct,我定义了以下结构-坐标结构本身就是父结构的成员 typedef struct _coord { double x; // time axis - seconds rather than samples double y; } t_coord; typedef struct _algosc { t_coord coords[COORD_COUNT]; //... struct continues be

我定义了以下结构-坐标结构本身就是父结构的成员

typedef struct _coord {
    double x;   // time axis - seconds rather than samples
    double y;
}   t_coord;

typedef struct _algosc {                    
    t_coord coords[COORD_COUNT];        
    //... struct continues beyond this but...
}   t_algosc;
我创建一个指向父结构的指针,然后分配内存。object_alloc是特定于别处定义的API(MAX5)的malloc类型函数。这一切都是工作,所以我不包括细节

static t_class *algosc_class;   // pointer to the class of this object

    t_algosc *x = object_alloc(algosc_class)
这是我希望传递coord结构数组的函数的声明

    void    au_update_coords(t_coord (*coord)[])
我将数组传递给函数,如下所示

au_update_coords(x->coords);
这一切都很好,但我收到了编译器警告

1>db.algosc~.c(363): warning C4047: 'function' : 't_coord (*)[]' differs in levels of indirection from 't_coord [4]'
1>db.algosc~.c(363): warning C4024: 'au_update_coords' : different types for formal and actual parameter 1

我想不出通过结构的正确方法。有人能帮忙吗。同样是为了我的启发,我会冒什么样的风险让它保持原样呢?

您需要传递一个指向数组的指针,所以您需要获取数组的地址,使其成为指向数组的指针,如下所示

au_update_coords(x->coords, otherArguments ...);
应该成为

au_update_coords(&x->coords, otherArguments ...);
但你不需要这样。如果您担心函数没有在适当的位置更改数组,请不要再担心它会更改数组,您需要从更改函数签名

void    au_update_coords(t_coord (*coord)[], otherArguments ...)

并直接传递数组,如中所示

au_update_coords(x->coords, otherArguments ...);

当然,您可能需要在访问数组的任何位置修复
au\u update\u coords()
函数。

您的示例声明包含七个参数,但您只使用一个参数调用函数。我想这是因为在删除问题中不必要的代码时没有完全通过?请更正。数组会自然衰减为指针,因此不需要将指针传递给数组,只需传递数组本身(您现在这样做),这当然必须反映在函数参数声明中(即,删除指针声明)。感谢ruakh-是的,现在更正。感谢Joachim-非常清楚,如果这是作为答案发布的,我会选择它作为答案。这行:“void au_update_coords(t_coord(*coord)[])”将传递一个指向t_coord类型的指针数组。我怀疑这不是你真正想做的。建议:“void au_update_coords(t_coord*coord)”您可能希望传递第二个参数,该参数指示coord数组
x->coords
不是可变长度数组,它具有固定维度
coord_COUNT
(结构无论如何不能包含VLA)@iharob否它不是;指向VLA的指针看起来像
T(*ptr)[n]
。这与
T(*ptr)[]
不同,后者是指向不完整数组类型的指针。谢谢matt-我没有发现这个细节。说得好。Iharob,如果你能删除对VLA的引用,我会将其保留为选定答案,否则这会误导其他找到它的人。。
au_update_coords(x->coords, otherArguments ...);