Andy Ross wrote:
Erik Hofman wrote:I'm certainly no guru but I believe you correctly state below why this doesn't
While compiling on IRIX I get the following error:
[...]
To be honnest I'm not quite sure what you're trying to do here.
The hash table needs two blocks allocated: one to hold the table nodes and one to hold the top-level table of "column" pointers. For efficiency, it packs them together into a single malloc'ed block. The standard type rules don't like this, so you end up doing a lot of casting.
error(1138): expression must have pointer-to-object type
h->table = ((void*)h->nodes) + sz*sizeof(struct HashNode);
Maybe it doesn't like the arithmetic on a void* (if a language guru knows whether you can add to a void*, please speak up). Try changing it to a char* and see if that fixes this one.
work when you said that pointer arithmetic works in units of the element
size. The type void does not have a size.
I believe (but will have to look it up) that your compiler is incorrectly complaining about the assignment from void* to struct HashNode**. I'm pretty sure this is legal in C, for purposes exactly like this one. But casts are easy to add.
Changing it to the following solves the problem: h->table = ((struct HashNode*)h->nodes) + sz*sizeof(struct HashNode);
But it does trigger another problem:
line 23: warning(1515): a value of type
"struct HashNode *" cannot be assigned to an entity of type
"struct HashNode **"
This one makes perfect sense. Because the type of h->table is a "struct HashNode**", but you put a case in saying that it was a "struct HashNode*". Regardless, doing this is a bug. Arithmetic on pointers in both C and C++ works in units of the structure size. That line is trying to add a number of bytes to the base address of the block to get a new address; your code adds that many structure sizes.
Instead, try this as a more verbose variant and see if it works. It adds an explicit cast to the type of the table, and uses a char* to get around the original error:
h->table = (struct HashNode**)(((char*)h->nodes) + sz*sizeof(struct HashNode));
You could do this but using again what you said about pointer arithmetic it can be reduced to:
h->table = (struct HashNode**) (h->nodes + sz);
You must have the parens around the addition since the cast has a higher precedence.
Andy
-- Russ
Conway's Law: "The structure of a system tends to mirror the
structure of the group producing it."
-- Mel Conway Datamation (1968)_______________________________________________ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
