Solved

pointer confusion in hash table

Posted on 2004-10-09
3
214 Views
Last Modified: 2012-05-05
HI expert(s)

I am getting really confused with all the pointers for a school assignment, and is unable to get help on a weekend.
I have a set of structs containing a number of different pointers:

typedef struct bucket *ListPtr;
typedef struct bucket *BucketPtr;
typedef struct conListNode *ListNodePtr;

typedef struct ipaddr
{
  int digit1, digit2, digit3, digit4;
}IPAddress;

typedef struct bucket
{
  int           size;
  ListPtr       listPtr;
}Bucket;

typedef struct connctnList
{
  int         tableSize_N;
  int         bucketThreshold_m;
  int         primeNo1_k1;
  int         primeNo2_k2;
  int         primeNo3_k3;
  int         primeNo4_k4;
  int         primeNo5_k5;
  BucketPtr   *bucketPtr;
}connctnList;

typedef struct conListNode
{
  IPAddress     ipAddress;
  int           portNumber;
  ListNodePtr   next;
}ConListNode;

When I use them in a function, eg:

int addConnection(connctnList *conList, IPAddress address, int port)
{
  int hashValue = INITIALISE;
  BucketPtr position;
  ListNodePtr current, previous, new;
  ...
  if (position == NULL)
  {
    conList->bucketPtr[hashValue]->size++;
    position = new;  <---------------------------------------this line
    return SUCCESS;
  }

I get this message for the line pointed to by an arrow:

"connctnList_HT.c:258: warning: assignment from incompatible pointer type"

I know it is because BucketPtr and ListNodePtr are different pointer types, but how can I re-structure the ADTs to resolve this.

Thanks in advance

kwy
0
Comment
Question by:kwy
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 500 total points
ID: 12269293
If it's unhappy with an explicit cast:
position=(BucketPtr)new;

try it thru a void:
position=(BucketPtr)((void)new);
0
 

Author Comment

by:kwy
ID: 12269393
thanks, but why the void ??
0
 
LVL 22

Expert Comment

by:cookre
ID: 12269491
Sometimes a compiler simply won't do a cast from type A to type B, but it never has problems going to or from void, so we use that as an intermediate.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question