gpt4 book ai didi

c - 指向 C 中 struct 的函数返回矩阵的指针

转载 作者:太空宇宙 更新时间:2023-11-04 08:08:03 26 4
gpt4 key购买 nike

我正在尝试为返回结构矩阵的函数指针创建 typedef。我试过:

typedef struct my_struct**  (*func)(void)
typedef struct my_struct[4][4] (*func)(void)

但它们都不起作用。我的结构矩阵初始化如下:

static struct my_struct matrix[4][4];

我的代码没有使用 typedef 的 2 个选项编译。我应该如何创建这个 typedef?谢谢。

最佳答案

无法返回数组。但是,您可以返回指向数组的指针。如果您想从函数中检索二维数组,则应返回此内容。

该函数将返回一个指向 4 个结构的数组的指针:

struct my_struct (*function(void))[4];

这种类型的类型定义:

typedef struct my_struct (*type(void))[4];
type* p = function;

关于c - 指向 C 中 struct 的函数返回矩阵的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41290611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com