1
I need to use the following structures without changing their file implementations .h
.
typedef unsigned long int chave_t;
typedef unsigned long int conteudo_t;
typedef struct entrada_hash{
chave_t chave;
conteudo_t * conteudo;
struct entrada_hash * proximo;
} entrada_hash_t;
typedef struct elemento_lista{
entrada_hash_t * elemento;
struct elemento_lista * proximo;
} elemento_lista_t;
typedef struct tabela_hash{
unsigned long int numero_elementos;
struct entrada_hash_t * armazenamento;
void * sincronizacao;
} hash_t;
However when initializing the hash table and trying to access any contents placed in its entry I get the following error:
hash_s.c: In function ‘ht_init’:
hash_s.c:18:3: error: invalid use of undefined type ‘struct entrada_hash_t’
hash->armazenamento[i]->chave = i;
^
hash_s.c:18:22: error: dereferencing pointer to incomplete type
hash->armazenamento[i]->chave = i;
^
The initialization of the variables I do as follows:
hash_t * ht_init(unsigned long tam) {
hash_t * hash ;
unsigned long i = 0;
hash = malloc(sizeof(hash_t));
hash->numero_elementos = tam;
hash->armazenamento = malloc (tam * sizeof(entrada_hash_t));
for(i=0;i<tam;i++){
hash->armazenamento[i]->chave = i;
}
return hash;
}
At first I had thought that the structures were not actually being imported from the archive. h, but if so the compiler would already give me error in trying to declare the same before the for
. So I believe I’m not assigning something necessary at some point within the function init_t
, someone can see what’s wrong?
found this related answer, https://forum.zwame.pt/threads/duvida-programcao-error-dereferencing-pointer-incomplete-type.493621/ but still, I can’t quite fit the problem.
– pmargreff