简体   繁体   中英

Dereferencing pointer to incomplete type C

Well, I'm getting this error and couldn't identify when i'm trying acess the fields.

In my bnum.c, i have the declaration of my struct:

    #include "bnum.h"

    struct num {
      char *vet;
      int tam;
    };

And in my bnum.h, I have:

    typedef struct num *b_num;

And in the main file I have:

    #include"bnum.h"
    int main(void){
    b_num b;
    b->tam = 5;

I'm using gcc on Linux Mint.

The main file does not have access to the structure definition, hence the error. You should move the definition

  struct num {
     char *vet;
     int tam;
  };

from .c to .h.

This is not a good-organized code. The struct declaration should be in the header file, this way any src file that will include the header will be familiar with that struct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM