incompatible type

This is a discussion on incompatible type within the C Programming forums, part of the General Programming Boards category; I'm getting an incompatible type in assignment error for the following code: ((hashNode *)t->data)[hashValue] = (hashNode *)calloc(sizeof(hashNode), 1); And then ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    incompatible type

    I'm getting an incompatible type in assignment error for the following code:

    ((hashNode *)t->data)[hashValue] = (hashNode *)calloc(sizeof(hashNode), 1);


    And then the same incompatible types in initialization:

    hashNode *previous = ((hashNode *)t->data)[hashValue];


    I am implementing a hash bucket with linked list and t is a generic structure and hashNode is a node for the linked list. HashValue is the value of the hashfunction so that I know which array spot to enter the hashvalue. I hope you guys understand what is going on here. Any advice would be great! thanks.

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    What's the actual compiler error?

    I think you're most likely trying to assign a pointer to a non-pointer. Also, you should never need to cast any m/c/realloc() calls.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    Registered User KidA's Avatar
    Join Date
    Nov 2005
    Location
    Ohio, USA
    Posts
    26
    data is declared as an array of what type?

    In the second statement you are assigning the hashNode* previous to the value contained in an element of the data array. If data is not an array of hashNode* then this would create a compiler error.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Since t->data is being casted, it might be an array of void pointers.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. incompatible pointer type?
    By kezman in forum C Programming
    Replies: 3
    Last Post: 04-22-2009, 05:42 PM
  2. typename madness
    By zxcv in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2006, 11:35 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21