繁体   English   中英

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

[英]Compiler Warning Passing array of structs (itself member of struct) to Function

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

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)

这是我希望将协调结构数组传递给的函数的声明

    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 ...)

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

并直接将数组传递为

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

当然,无论您在哪里访问阵列,都可能需要修复au_update_coords()函数。

暂无
暂无

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

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