我正在尝试将 libbeanstalkd 集成到嵌入式系统中,因此我必须进行一些小改动。到目前为止,我已经能够替换/修复一些特定于操作系统的代码,但后来我遇到了这个错误。在“表达式必须是指向完整对象类型的指针”之前,我已经修复了这些类型的错误,但除了我确定宏的标头和使用的对象是使用该宏这一事实之外,真正让我感到困惑的是在抛出编译器错误之前的几行。有人可以帮助我了解问题所在吗?
资源arrayqueue.h
#ifndef ARRAYQUEUE_H
#define ARRAYQUEUE_H
#define AQ_DEFINE_STRUCT(struct_name, node_type) \
struct struct_name { \
node_type *nodes; \
size_t size; \
size_t used; \
off_t front; \
off_t rear; \
}
#define AQ_NODES_FREE(q) ( (q)->size - (q)->used )
#define AQ_FULL(q) ( (q)->used == (q)->size )
#define AQ_EMPTY(q) ( (q)->used == 0 )
#define AQ_REAR_(q) ( (q)->nodes + (q)->rear )
#define AQ_REAR(q) ( AQ_EMPTY(q) ? NULL : AQ_REAR_(q) )
#define AQ_FRONT_(q) ( (q)->nodes + (q)->front )
#define AQ_FRONT(q) ( AQ_FULL(q) ? NULL : AQ_FRONT_(q) )
#define AQ_DEQ_FIN(q) ( (q)->rear = ( (q)->rear + 1 ) % (q)->size, (q)->used-- )
#define AQ_ENQ_FIN(q) ( (q)->front = ( (q)->front + 1 ) % (q)->size, (q)->used++ )
#endif /* ARRAYQUEUE_H */
来源ioqueue.h
:
#ifndef _IOQUEUE_H
#define _IOQUEUE_H
#include <stddef.h>
#include <vsocket.h>
#include "arrayqueue.h"
#include "verixmissing.h"
struct _ioq_node {
struct iovec *vec;
int autofree;
};
AQ_DEFINE_STRUCT(_ioq, struct _ioq_node);
typedef struct _ioq ioq;
typedef struct _ioq_node ioq_node;
#define IOQ_NODES_READY(q) ((q)->used ? ( (q)->front <= (q)->rear ? (q)->size - (q)->rear : (q)->used ) : 0)
#define IOQ_PEEK_POS(q, i) ((AQ_REAR_(q)+i)->vec)
#define IOQ_REAR_(q) IOQ_PEEK_POS(q,0)
#define IOQ_REAR(q) (AQ_EMPTY(q) ? NULL : IOQ_REAR_(q))
void ioq_enq_(ioq *q, void *data, ssize_t data_len, int autofree);
int ioq_enq(ioq *q, void *data, ssize_t data_len, int autofree);
ssize_t ioq_dump(ioq *q, int fd);
ioq *ioq_new(size_t size);
void ioq_free(ioq *q);
#endif /* _IOQUEUE_H */
来源ioqueue.c
:
#include <stdlib.h>
#include <vsocket.h>
#include "arrayqueue.h"
#include "ioqueue.h"
...
ssize_t ioq_dump(ioq *q, int fd)
{
size_t bytes_expected = 0, nodes_ready = IOQ_NODES_READY(q), i;
ssize_t bytes_written, nodes_written = 0;
for (i = 0; i < nodes_ready; ++i)
bytes_expected += IOQ_PEEK_POS(q,i)->iov_len;
if ( ( bytes_written = writev(fd, IOQ_REAR_(q), nodes_ready) ) < bytes_expected )
switch (bytes_written) {
case -1:
return -1;
default:
while ( ( bytes_written -= IOQ_REAR_(q)->iov_len ) > 0 ) {
IOQ_DUMP_FIN(q, 1);
++nodes_written;
}
if ( bytes_written < 0 ) {
IOQ_REAR_(q)->iov_base += IOQ_REAR_(q)->iov_len + bytes_written;
^---------------------- ERROR!
IOQ_REAR_(q)->iov_len = -bytes_written;
}
return nodes_written;
}
else {
IOQ_DUMP_FIN(q, nodes_ready);
return nodes_ready;
}
}
错误:
"..\Source\libs\libbeanstalkd\ioqueue.c", line 125: Error: #852: expression must be a pointer to a complete object type
IOQ_PEEK_POS(q, 0)->iov_base += IOQ_REAR_(q)->iov_len + bytes_written;
^
如果有帮助,Eclipse 会将宏扩展为:((( (q)->nodes + (q)->rear )+0)->vec)