Thread: Implicit cast to const

  1. #1
    Registered User
    Join Date
    Mar 2011

    Implicit cast to const

    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:

    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:

    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.

      it_begin                     it_end
          |                           |
          v                           v
    list ---> element1 ---> element2 ---> NULL

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Is there any particular reason you don't just use a double linked list, instead of maintaining a separate list of pointers? What's the point of even having a linked list, if you're just keeping an array of pointers to all of them? That defeats the purpose of the list.

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Long Beach, CA

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compile-time vs. runtime const multiplication
    By CodeMonkey in forum C++ Programming
    Replies: 5
    Last Post: 08-21-2010, 05:32 PM
  2. stdio.h?
    By kiros88 in forum C Programming
    Replies: 5
    Last Post: 05-21-2010, 07:09 PM
  3. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM