小编kop*_*ecs的帖子

C - 返回一个指向二维数组的指针

我正在尝试为结构的二维数组编写吸气剂。我尝试了各种解决方案,而我的 IDE 抱怨所有这些。

static history_t history[3][6];

history_t **get_history(){
    return history;
};
Run Code Online (Sandbox Code Playgroud)

根据我的理解,这是正确的。数组数组是指向指针的指针。但是,我的 IDE 抱怨指针类型不兼容。我一直无法找到任何历史签名和访问器的组合,这使我能够返回任何有用的东西。

这在 C 中是可能的吗?

warning: returning 'history_t (*)[6]' {aka 'struct <anonymous> (*)[6]'} from a function with incompatible return type 'history_t **' {aka 'struct <anonymous> **'} [-Wincompatible-pointer-types]
     return history;
Run Code Online (Sandbox Code Playgroud)

所以,我的函数不是返回history_t **,而是history_t *[6]。但是,重新定义要返回的签名history_t*[6]也不起作用。

c arrays

0
推荐指数
1
解决办法
95
查看次数

标签 统计

arrays ×1

c ×1