Solved

pointer confusion in hash table

Posted on 2004-10-09
3
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

687 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