Hi community,
My first question on tihs forum is about implicit casting from a non constant pointer to a constant pointer. Í thought this would be the case. But my compiler(gcc) brings up this.
game.c: In function ‘main’:
game.c:77: warning: passing argument 1 of ‘SK_next_it’ from incompatible pointer type
vertex_buffer.h:16: note: expected ‘struct sk_vertex_list_entry * const**’ but argument is of type ‘struct sk_vertex_list_entry ***’
It's a bit complex cause I have a pointer to a pointer to a pointer here. So I'm not sure If I totaly understand what's going on exactly.
Because the first thing you think, ehen you see something like this is. Eh, are you really sure you need this? So here's a short explanation why I ended up with something like this.
First my typedefs, representing iterators for a singly linked list:
Code:
typedef struct sk_vertex_list_entry ** SK_IT;
typedef struct sk_vertex_list_entry * const * SK_CONST_IT;
There should be an implicit cast from SK_IT to SK_CONST_IT. SK_IT should be useable with all functions with an SK_CONST_IT argument.
The function, throwing the warning is:
Code:
void SK_next_it(CONST_IT *it)
{
(*it) = &(**it)->next;
}
It moves the iterator to the next list element.
Why a pointer to a pointer and not a pointer to an element?
The iterator pointing to the next pointer of the previous element. This way, it's possible to insert an element before and/or after an element, like in a doubly linked list.
Code:
it_begin it_end
| |
v v
list ---> element1 ---> element2 ---> NULL