Dynamic array of structs and function call f(const struct_type *const data[])

前端 未结 4 1318
说谎
说谎 2021-01-15 20:09

The following code warns about incompatible type. What is the proper way to solve this code?

thanks

typedef struct a_struct struct_type;

void f(cons         


        
4条回答
  •  半阙折子戏
    2021-01-15 20:37

    f expects to get as input an array of pointers (const struct_type* []). You pass a pointer to a pointer of struct (const struct_type**).

    The best thing to do, IMO, is to change the signature of f to:

    void f(const struct_type *const* data);
    

    Why do you need to pass arrays as arguments to functions?

提交回复
热议问题