[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

pointer confusion in hash table

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project

872 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