预期的 struct foo* 但参数是函数指针的 struct foo* 类型
expected struct foo* but argument is of type struct foo* for function pointers
我有两个函数指针类型定义和两个结构,struct pipe_s
和 struct pipe_buffer_s
定义如下:
typedef void (*pipe_inf_t)(struct pipe_buffer_s *);
typedef void (*pipe_outf_t)(struct pipe_buffer_s *);
struct
pipe_buffer_s
{
size_t cnt; /* number of chars in buffer */
size_t len; /* length of buffer */
uint8_t *mem; /* buffer */
};
struct
pipe_s
{
struct pipe_buffer_s buf;
uint8_t state;
pipe_inf_t in; /* input call */
pipe_outf_t out; /* output call */
};
在我的实现中,我有一个尝试调用函数 in
:
的函数
void
pipe_receive(struct pipe_s *pipe)
{
pipe_inf_t in;
in = pipe->in;
in(&pipe->buf);
}
但我收到了奇怪的错误:
pipe.c:107:5: note: expected 'struct pipe_buffer_s *' but argument is of type 'struct pipe_buffer_s *'
这对我来说毫无意义。据我所知 告诉 ,我没有搞砸并尝试使用未定义长度的结构,因为我在这里只使用指针。我想我的 typedef 可能做错了什么...
将 typedef 更改为 typedef void (*pipe_inf_t)(int);
并调用 in(5)
效果很好。
如果我将 in
和 out
移动到 pipe_buffer_s
结构中并从那里调用它们,我会得到同样的错误,所以位置似乎并不重要。
有什么想法吗?
在引用它之前添加pipe_buffer_s
的定义。这可能是一个不完整的类型:
#include <stdlib.h>
#include <stdint.h>
struct pipe_buffer_s; // Incomplete definition
typedef void (*pipe_inf_t)(struct pipe_buffer_s *);
typedef void (*pipe_outf_t)(struct pipe_buffer_s *);
struct
pipe_buffer_s
{
size_t cnt; /* number of chars in buffer */
size_t len; /* length of buffer */
uint8_t *mem; /* buffer */
};
struct
pipe_s
{
struct pipe_buffer_s buf;
uint8_t state;
pipe_inf_t in; /* input call */
pipe_outf_t out; /* output call */
};
// In my implementation, I have a function that attempts to call the function in:
void
pipe_receive(struct pipe_s *pipe)
{
pipe_inf_t in;
in = pipe->in;
in(&pipe->buf);
}
我有两个函数指针类型定义和两个结构,struct pipe_s
和 struct pipe_buffer_s
定义如下:
typedef void (*pipe_inf_t)(struct pipe_buffer_s *);
typedef void (*pipe_outf_t)(struct pipe_buffer_s *);
struct
pipe_buffer_s
{
size_t cnt; /* number of chars in buffer */
size_t len; /* length of buffer */
uint8_t *mem; /* buffer */
};
struct
pipe_s
{
struct pipe_buffer_s buf;
uint8_t state;
pipe_inf_t in; /* input call */
pipe_outf_t out; /* output call */
};
在我的实现中,我有一个尝试调用函数 in
:
void
pipe_receive(struct pipe_s *pipe)
{
pipe_inf_t in;
in = pipe->in;
in(&pipe->buf);
}
但我收到了奇怪的错误:
pipe.c:107:5: note: expected 'struct pipe_buffer_s *' but argument is of type 'struct pipe_buffer_s *'
这对我来说毫无意义。据我所知 告诉 ,我没有搞砸并尝试使用未定义长度的结构,因为我在这里只使用指针。我想我的 typedef 可能做错了什么...
将 typedef 更改为 typedef void (*pipe_inf_t)(int);
并调用 in(5)
效果很好。
如果我将 in
和 out
移动到 pipe_buffer_s
结构中并从那里调用它们,我会得到同样的错误,所以位置似乎并不重要。
有什么想法吗?
在引用它之前添加pipe_buffer_s
的定义。这可能是一个不完整的类型:
#include <stdlib.h>
#include <stdint.h>
struct pipe_buffer_s; // Incomplete definition
typedef void (*pipe_inf_t)(struct pipe_buffer_s *);
typedef void (*pipe_outf_t)(struct pipe_buffer_s *);
struct
pipe_buffer_s
{
size_t cnt; /* number of chars in buffer */
size_t len; /* length of buffer */
uint8_t *mem; /* buffer */
};
struct
pipe_s
{
struct pipe_buffer_s buf;
uint8_t state;
pipe_inf_t in; /* input call */
pipe_outf_t out; /* output call */
};
// In my implementation, I have a function that attempts to call the function in:
void
pipe_receive(struct pipe_s *pipe)
{
pipe_inf_t in;
in = pipe->in;
in(&pipe->buf);
}