Hello Group,
Consider the following code fragment:
#define PSM_TABLESIZE 2441 /* size of hash table (prime number) */
#define uint32 unsigned long int
typedef struct psmalloc_table_tag
{
void *p; /* pointer to data */
uint32 size; /* size of memory block */
uint32 flags; /* operational flags */
struct psmalloc_table_tag *next; /* pointer to next record */
} psmalloc_table_t;
typedef struct psmalloc_tag
{
uint32 valid; /* valid struct flag */
uint32 count; /* number of entries used */
uint32 slimit; /* allocation size limit */
uint32 tlimit; /* total allocation limit */
uint32 tsize; /* total size count register */
uint32 flags; /* flags to use if PSM_SEC_USEFLAGS */
int security; /* sets default security mode */
psmalloc_table_t *ht[PSM_TABLESIZE]; /* hash table */
} psmalloc_t;
/* computes hash value from pointer */
uint32 psm_hashkey(void *p)
{
uint32 hash;
151: hash = PSM_TABLESIZE * ((int)p * .618 % 1);
return(hash);
}
Gcc gives the following error about the above line: psmalloc.c:151:
error: invalid operands to binary %
/* **** HASH TABLE MANAGEMENT **** */
/* adds the specified entry to the hash table */
int psm_tableadd(psmalloc_t *state, void *ptr, uint32 size, uint32 flags)
{
uint32 hash;
psmalloc_table_t *p;
hash = psm_hashkey(ptr);
/* locate position in table and allocate memory for it */
185: if (state->ht[hash] == NULL)
{
/* table position empty */
188: state->ht[hash] = malloc(sizeof(psmalloc_table_t));
And here it gives errors as well:
psmalloc.c:185: error: invalid operands to binary ==
psmalloc.c:188: error: incompatible types in assignment
What I am trying to do is declare and array of pointers of type
psmalloc_table_t named ht in the structure. But when I try to reference
the pointers themselves, gcc keeps flagging it as an error. I did check
the book, and so far everything looks ok. I did look at the FAQ about
these problems and I didn't really find anything that applied to this
situation. What am I missing?
--
Daniel Rudy
Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m
Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep