CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    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.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    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

  3. #3
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Re: Header does not see definition

    Thank you very much for your response.

  4. #4
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    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?

  5. #5
    Join Date
    Feb 2006
    Location
    Croatia - Zagreb
    Posts
    459

    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?

  6. #6
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Re: Header does not see definition

    Still getting errors. Maybe I must follow close what includes what...

  7. #7
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Re: Header does not see definition

    Solved thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured