简体   繁体   中英

Why do I get “increment of pointer to unknown structure”?

I'm trying to bulid a structure named "cache", which holds a container (an array of type List which is already implemented) and an iterator. when I'm trying to make the iterator point at the next List in the container I get "increment of pointer to unknown structure" and "arithmetic on pointer to an incomplete type". I would love an explanation as to what I'm doing wrong:

List is typedefed as follows:

typedef struct List_t *List;

so List is a pointer to a List_t structure.

Cache is defined as follows:

typedef struct cache_t* Cache;

struct cache_t {
    List* container;
    int cache_size;
    List iterator;
};

so iterator is a List which is a pointer to a List_t in an array (container). What I'm trying to do is:

cache->iterator ++; //cache is an object of type Cache

which, as far as I know, should move iterator by sizeof(List) to the next List in the array. so why am I getting errors?

thanks!

The pointer is not incremented by sizeof(List) but by sizeof(struct List_t) . The definition of struct List_t is not there in your source, and is thus an incomplete type. This is the reason for the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM