3
votes
// set all values in the hash table to null
for(int i = 0; i < HASH_SIZE; i++)
{
    hashtable[i] = NULL;
}

I keep getting this error message in response to hashtable[i]:

assignment makes integer from pointer without a cast [-Werror]

Why?

2

2 Answers

7
votes

If hashtable is an array of integers then hashtable[i] expects an integer and NULL is a pointer.

So you're trying to assign a pointer value to an integer variable(without a cast), this is usually just a warning but since you have -Werror all warnings turn into errors.

Just use 0 instead of NULL.

1
votes

NULL is defined as (void*)0 in stddef.h

#ifndef _LINUX_STDDEF_H
#define _LINUX_STDDEF_H

#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif

#endif

If the hashtable is integer array, like

#include <stdio.h>
#define HASH_SIZE 100
int main()
{
int i = 0, hashtable[HASH_SIZE];
for(i = 0; i < HASH_SIZE; i++)
{
    hashtable[i] = NULL;
}
return 0;
}

this warning: assignment makes integer from pointer without a cast will be shown.