我正在使用 VS 2013 和 c 处理现有项目。
我来到这个函数,但我不明白它是什么意思:
int (*Read)(void *p, void *buf, size_t *size);
我所知道的是它是一个返回指向 int 的指针的函数,但我想知道:
- Why void as type means when dealing with parameters (maybe a generic pointer ?)
- What (*Read) means in this case (i think it's a cast !)
要真正知道我在这里使用的是完整的依赖项:
typedef struct
{
#ifdef USE_WINDOWS_FILE
HANDLE handle;
#else
FILE *file;
#endif
} CSzFile;
typedef struct
{
int (*Read)(void *p, void *buf, size_t *size);
} ISeqInStream;
typedef struct
{
ISeqInStream s;
CSzFile file;
} CFileSeqInStream;
CFileSeqInStream inStream;
最终目标是打开一个文件,但为什么要这么复杂!
任何帮助将不胜感激,谢谢。
最佳答案
What i know is it's a function that return pointer to int
不,它是指向函数的指针,将以下参数类型作为输入:
- 第一个参数的类型:
void*
- 第二个参数的类型:
void*
- 第三个参数的类型:
size_t*
并返回一个 int
值作为输出。
关于c - (*Read)(void *p, void *buf, size_t *size); 中返回类型的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35197699/