[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

pointer confusion in hash table

Posted on 2004-10-09
3
Medium Priority
?
224 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 2000 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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…
Starting up a Project

650 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