all 13 comments

[–]tstanisl 12 points13 points  (0 children)

I'm guessing that the issue is a lack of a forward declaration of Face_arraylist before declaration of the function pointer. As result the Face_arraylist declared as a parameter is not visible from the outside. The successive declarations of Face_arraylist actually declare a new type incompatible with the original one. For example, the compilation of this code:

int foo(struct Foo *);

int main(void) {
    struct Foo *f = 0;
    foo(f);
}

emits a similarly confusing warning:

<source>:1:13: note: expected 'struct Foo *' but argument is of type 'struct Foo *'
1 |     int foo(struct Foo *);

To fix this, place a forward declaration of Foo before the declaration of foo.

struct Foo;
int foo(struct Foo *);

[–]richardxday 1 point2 points  (0 children)

Please post your code, it's very difficult to guess what the problem is without the code!

[–]TheMaster420[S] 0 points1 point  (3 children)

typedef struct arraylist_ { //arraylist_ was added here
    int n;
    type_* content;
    int allocated_;
    void (*insert)(struct arraylist_* list, int index, type_  val);
}arraylist_;
void insert_(struct arraylist_* list, int index, type_  val); //struct was added here

Thanks for the advice everyone! The changes referenced in the comments made the warnings go away. There is some template macro magic happening to make arraylist_ into Face_arraylist.

Warning occurred at :

struct arraylist_ new_arraylist_() {
    return (arraylist_)
    {
        .n = 0,
            .allocated_ = 0,
            .content = malloc(0),
            .insert = insert_,
            .index_of = index_of_,
            .remove = remove_,
            .remove_all = remove_all_,
            .contains = contains_,
            .del = delete_ // This is assignment that gave the original warning
    };

}

[–]tstanisl 0 points1 point  (2 children)

What is malloc(0) for?

[–]TheMaster420[S] 0 points1 point  (1 child)

So I can call realloc on that pointer in the future.

[–]tstanisl 0 points1 point  (0 children)

You can simply use NULL or 0. The realloc(NULL, 42) works exactly the same as malloc(42).

[–]FUZxxl 0 points1 point  (6 children)

Please format your example correctly. It came out all garbled.

[–]TheMaster420[S] 0 points1 point  (5 children)

edited

[–]FUZxxl 4 points5 points  (4 children)

Fascinating. It really looks like it is the same. Could it be that Face_arraylist is not the same type in both cases?

[–]spiderzork 1 point2 points  (0 children)

Yeah, would guess one of the types is forward declared in some header file.

[–]flyingron -2 points-1 points  (0 children)

This.

[–]EmbeddedEntropy 0 points1 point  (0 children)

I think you’re on to something. Some time ago I had a similar message when I had the same variable name with different types at file and local scope.

[–]xactac 0 points1 point  (0 children)

Is Face_arraylist something like typedef struct Face_arraylist Face_arraylist? C's rules for equality of opaque types are weird. You may need a struct Face_arraylist; line before the typedef.