c - 错误 : function declared as function returning function

标签 c linux gnu porting

我正在将 Windows 程序集移植到 Linux。我有一些代码要移植。我实际上是 linux 中 C 的新手。我知道 C 基础知识是一样的!

typedef struct sReader
{
    pReaderAddRef addRef;
    pReaderDelRef delRef;
}pReader, *pSReader;

typedef long (*pReaderAddRef)(struct sReader *);
typedef long (*pReaderDelRef)(struct sReader **);

上面的代码给出了错误'pReaderAddRef' declared as function returning a function

我了解回调函数的工作方式。但我真的不知道如何解决这个错误。

请帮忙。

最佳答案

虽然我不明白你原来的错误信息 - 我明白了

f.c:3:5: error: unknown type name ‘pReaderAddRef’
f.c:4:5: error: unknown type name ‘pReaderDelRef’

使用您的原始代码 -

看来您弄错了顺序:为了使用函数指针,您必须定义它们。

struct sReader; // incomplete type, but ready to be used

//alternatively:
typedef struct sReader pReader, *pSReader; // taken from your edit, but these prefixes are misleading

typedef long (*pReaderAddRef)(struct sReader *); // or mytypename
typedef long (*pReaderDelRef)(struct sReader **);

struct sReader
{
    pReaderAddRef addRef; // Now you can use them
    pReaderDelRef delRef;
}

关于c - 错误 : function declared as function returning function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21475870/

相关文章:

c - 将 Mender.io 与 Azure IOT 中心集成

linux - struct task_struct中的字段 'on_cpu'和struct thread_info中的字段 'cpu'是什么意思?

C:如何为字符串分配准确数量的字节?

连接 C 字符串

linux - 如何在 Linux 内核中使用 RSA

C: 如果文件描述符被删除,阻塞读取应该返回

linux - 为什么Linux系统时间每6个月加减一小时?

linux - 从输入打印特定列的命令

linux - tr 命令 - 如何用实际的换行符 (\n) 替换字符串 "\n"

c++ - 结构体(数组)中出现次数最多的数字