|
-
June 5th, 2006, 12:48 AM
#1
Header does not see definition
Well I can't compile the following code on header (called COMBTEX.h) (im using GCC):
Code:
#ifndef COMBTEX_H
#define COMBTEX_H
#include <limits.h>
#include "lines.h"
#include "fields.h"
/*----------------------- defines y macros -------------------------*/
/* tipo BOOL */
#define TRUE 1
#define FALSE 0
typedef int BOOL;
/*-------------------------- estructuras ---------------------------*/
/* CONFIG: almacena los seteos del programa */
typedef struct
{
BOOL verbose; // salida de combinacion por pantalla?
char inputFile[PATH_MAX]; // nom. archivo de entrada
char outputFile[PATH_MAX]; // nom. archivo de salida
char dataFile[PATH_MAX]; // nom. archivo de datos
} CONFIG;
/* prototipo de funciones */
void initstruct( CONFIG* , TEXTBUFFER*, FIELDLIST*);
´
In the link marked red, the compiler says:
combtex.h:36: error: syntax error before "TEXTBUFFER"
We'll TEXTBUFFER is defined on "lines.h" (it's included properly on the above header). Here it is:
Code:
#ifndef LINES_H
#define LINES_H
#define TEXT_ENDMARK '*'
#define MAX_DIGITS 6
#define MAX_LINE 100 // caracteres maximos de linea
#include "combtex.h"
/* TEXTBUFFERS: estructura que contiene los buffers de texto y estado del mismo
de los mismos */
typedef struct _textbuf
{
int numTextLines; // numero de lineas de texto fuente
char* linebuffer[];
}
TEXTBUFFER;
void doInputtext(CONFIG* , TEXTBUFFER*);
BOOL loadtextfile(char*, TEXTBUFFER *);
void loadtextin(TEXTBUFFER* );
void editbuffer(TEXTBUFFER* );
void viewbuffer(TEXTBUFFER* );
void freebuffer(TEXTBUFFER* );
#endif //LINES_H
The problem is that in LINES.H i need the definition of CONFIG* for doInputtext function. That is in the first header...
I'm getting a problem on cyclic-header includes?
Thank you very much for your help.
-
June 5th, 2006, 01:02 AM
#2
Re: Header does not see definition
Yes, it is cyclic as "lines.h" includes "combtex.h", which includes "lines.h", which includes "combtex.h", etc.
You should forward declare your structures and not include combtex.h in lines.h.
Code:
#ifndef LINES_H
#define LINES_H
#define TEXT_ENDMARK '*'
#define MAX_DIGITS 6
#define MAX_LINE 100 // caracteres maximos de linea
/* TEXTBUFFERS: estructura que contiene los buffers de texto y estado del mismo
de los mismos */
typedef struct _textbuf
{
int numTextLines; // numero de lineas de texto fuente
char* linebuffer[]; // not legal C++ or ANSI C (pre C99)
} TEXTBUFFER;
struct CONFIG; // forward declare
void doInputtext(CONFIG* , TEXTBUFFER*);
BOOL loadtextfile(char*, TEXTBUFFER *);
void loadtextin(TEXTBUFFER* );
void editbuffer(TEXTBUFFER* );
void viewbuffer(TEXTBUFFER* );
void freebuffer(TEXTBUFFER* );
#endif //LINES_H
Another thing:
Code:
typedef struct _textbuf
{
int numTextLines; // numero de lineas de texto fuente
char* linebuffer[];
} TEXTBUFFER;
If you want this to be C++ code or ANSI C previous to the C99 specfication, you must get rid of the "char* linebuffer[]", since it is not legal C++ and is not legal ANSI C code as defined by the pre C99 specfication.
(Compile using strict ANSI invoked for gcc).
Regards,
Paul McKenzie
-
June 5th, 2006, 01:20 AM
#3
Re: Header does not see definition
Thank you very much for your response.
-
June 5th, 2006, 01:27 AM
#4
Re: Header does not see definition
Wow, still does not works...
typedef struct
{
int numTextLines; // numero de lineas de texto fuente
char* linebuffer[];
} TEXTBUFFER;
struct CONFIG; // forward
void doInputtext(CONFIG* , TEXTBUFFER*); <--- HERE
int loadtextfile(char*, TEXTBUFFER *);
GCC message is:
lines.h:29: error: syntax error before '*' token
..Are you sure it's possible to use forward declarations in ANSI C?
-
June 5th, 2006, 01:41 AM
#5
Re: Header does not see definition
You should get rid of the char* linebuffer[]; just as Paul said. Try using char **linebuffer or use std; and as for your problem, try using extern keyword or just move that struct to the lines file.
You just divided by zero, didn't you?
-
June 5th, 2006, 01:59 AM
#6
Re: Header does not see definition
Still getting errors. Maybe I must follow close what includes what...
-
June 5th, 2006, 02:06 AM
#7
Re: Header does not see definition
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|