2

I have the following code and I am getting an error that says the parameter map has an incomplete type. The variable strings is an smap declared as an extern in one of the header files included where the following code resides.

How can I fix this, or what does the error mean, or what are common causes for this error?

void print_strings(smap map);

void emit_strings(AST *ast) {
/* TODO: Implement me. */
    printf(".data\n");
    print_strings(strings);
}

void print_strings(smap map){
    for (size_t i = 0; i < map -> num_buckets; i += 1) {
        for (size_t j = 0; j < map -> buckets[i].num_pairs; j+=1) {
            printf("str%d:  .asciiz  %c\n",label_count,map ->buckets[i].pairs[j].key);
            label_count ++;
        }
    }

    label_count = 0;
}
Austin Mullins
  • 7,307
  • 2
  • 33
  • 48

1 Answers1

3

I previously posted an incorrect answer, but user @mafso graciously steered me back in the right direction.

The problem I overlooked before is that your print_strings function attempts to directly access member variables of the smap type. Since this is an incomplete type (i.e. it is defined in a separate source file), you cannot do this. You need to work with whatever functions are declared in the header in order to access the buckets and their internal values.

A typical header might look like this:

#ifndef SMAP_H
#define SMAP_H

#include "bucket.h"
#include <stdlib>

typedef struct string_map *smap;

smap smap_create(size_t num_buckets);
bucket *smap_get_buckets(smap map):

void *smap_add_bucket(smap map, bucket b);

#endif

In this example, instead of using map->buckets to access the buckets member, you would call the getter: smap_get_buckets(map).

The truth is, this is all speculation, because you still haven't provided any hints about the files that declare and define smap.

Austin Mullins
  • 7,307
  • 2
  • 33
  • 48