Reputation: 2923
I have my file.h
:
#ifnotdef _FILE_H_
#define _FILE_H_
#include "lista2.h"
struct texto{
int col_cursor;
int lin_cursor;
lista2* texto;
int tecla;
};
typedef struct texto Texto;
#endif //_FILE_H_
And I have my file.c
#include "file.h"
#include "lista2.h"
void recua_linha(Texto* t){
if(!(t->texto->corrente == t->texto->primeiro))
t->lin_cursor--;
}
lista2.h
#ifndef _LISTA2_H_
#define _LISTA2_H_
typedef struct lista2 lista2;
typedef struct elemento elemento;
#endif //_LISTA2_H_
lista2.c
#include "lista2.h"
struct elemento{
dado_t str;
elemento* ant;
elemento* prox;
};
struct lista2{
elemento* primeiro;
elemento* ultimo;
elemento* corrente;
};
But when I try to access any member of Texto
I get
Dereferencing pointer to incomplete type
I know it means that: The Program knows the Type but cant see it's implementation. I just can't know why or how to solve it.
Ps: I also need to access Texto
.members in main.c
file.
Upvotes: 1
Views: 529
Reputation: 73366
Take this piece of code from file.c:
t->texto->corrente
with t
being a Texto
struct. Now, from file.h, we have that this:
lista2* texto;
is a member of Texto
struct. Now we have to look at what file.c knows about lista2
. We have to look at the headers included in file.c, i.e. file.h and lista2.h. The first doesn't have anything relevant. The second however, does have this: typedef struct lista2 lista2;
, which helps. But, you are requesting a data member named corrente
, but lista2.h does not provide any info about the data members of lista2
, thus you should receive an error similar to this:
error: dereferencing pointer to incomplete type
because all file.c knows is the typedef
it sees in lista2.h.
In order to do what you want, you should modify your lista2.h like this:
#ifndef _LISTA2_H_
#define _LISTA2_H_
// moved it here, in order to use just 'elemento'
typedef struct elemento elemento;
struct elemento {
// I do not know what dato_t is...discarded
elemento* ant;
elemento* prox;
};
struct lista2 {
elemento* primeiro;
elemento* ultimo;
elemento* corrente;
};
typedef struct lista2 lista2;
#endif //_LISTA2_H_
leaving lista2.c empty. Also notice that I do not see why to add a tab before the stucts (the indentation starts from the first column of the file), so I removed it.
By the way, in file.h, maybe you would like to change this
#ifnotdef _FILE_H_
to this
#ifndef _FILE_H_
since you should receive this
Invalid preprocessor directive: ifnotdef
Notice that in order to access Texto
from main()
, you should include file.h in the main file.
Tip: A very good habit is to use a language that the community can (fully) understand in your code (English!) and you probably, if you need to develop code in the future for real world applications, usage of English is a must.
Upvotes: 1