Solved

pointer confusion in hash table

Posted on 2004-10-09
3
208 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now