質問

I'm attempting to integrate libbeanstalkd into an embedded system so I'm having to make some minor changes. So far I've been able to replace/fix some OS specific code but then I came to this error. I've fixed these type of errors before "expression must be a pointer to a complete object type" but what's really getting me aside from the fact that I'm sure the header for the macro and the used objects is that this macro is used a few lines BEFORE where the compiler error is thrown. Can someone help me understand what the issue is?

Source 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 */

Source 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 */

Source 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;
    }
}

Error:

"..\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;
                    ^

If it helps, Eclipse expands the macro to: ((( (q)->nodes + (q)->rear )+0)->vec)

役に立ちましたか?

解決 2

So I've found the problem... It appears that the real problem is that this method is attempting to increment the address of the buffer for the socket but the struct has iov_base defined as void * so the compiler doesn't know how to increment. (Got the answer from Error: expression must be a pointer to a complete object type (?))

iovec declaration:

struct iovec
{
    void *iov_base; // starting address of buffer
    int iov_len;  // size of buffer
};

The solution would be to cast it to a known type but unfortunately I don't know the type...

他のヒント

It is possible that struct iovec is not defined in your code somehow.

struct _ioq_node {
    struct iovec *vec; // <--------
    int    autofree;
};

Dump the preprocessor output and check for the definition. Take the gcc command line and replace -c option with -E (and set -o to wherever you want the output to go).

gcc -E -o <op> ...
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top