Odd error on header file inclusion

This is a discussion on Odd error on header file inclusion within the C Programming forums, part of the General Programming Boards category; Hey all! I just got some strange error when including a header file. It's a lot of code, but I'm ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    6

    Odd error on header file inclusion

    Hey all!

    I just got some strange error when including a header file. It's a lot of code, but I'm really clueless on why this happens and how to fix it.

    Full code: http://www.sitiodosnetos.com/v3.6.zip
    (most comments are in portuguese, apologies for that)

    I have a structure 'line', which will contain a dynamic array of pointers to structure 't_location'. Structure 't_location' will also have a dynamic array of pointers to structure 'line'.
    Each structure is declared in a separate file (line.h and t_location.h), along with specific function prototypes that belong to each of the structures.
    So far no problem, since the C compiler won't complain as they are pointers to undeclared structures.

    When I '#include "line.h"' at t_location.h, no problem at all, everything compiles like it should.
    When I '#include "t_location.h"' at line.h, some very strange errors happen:
    Code:
    user@pc-name:~/directory$ make all
    gcc -ansi -pedantic -Wall -c -main.c
    In file included from line.h:8
                     from gamearea.h:8
                     from main.h:12
                     from main.c:1
    t_location.h:12: error: expected specifier-qualifier-list before 'Line'
    t_location.h:15: error: expected ')' before '*' token
    t_location.h:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
    t_location.h:23: error: expected delcaration specifiers or '...' before 'Line'
    make: *** [main.o] Error 1
    where line:h:8 contains '#include "t_location.h"' only.

    Problem context:
    This is a tetris-related application. It will read a list of moves and will output the final state of the game (unlimited lines), plus an integer 'score', the number of lines printed, the content of the line in the median position of a insert-sorted (free positions removed) list of deleted lines, plus information about every piece that remains fully in the game.

    To archieve this, every line will have a variable-sized array that will point to information about the pieces in the line.

    Consequently, each piece will have a veriable-sized array that will point to the lines the piece is currently in (to prevent double-eliminations of the same piece).

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
      /* line.h */
    typedef struct Line {     
    	struct Line* previous;
    	struct Line* next;
    	char column[NUM_COLUNAS];
    	struct t_location* *pieces;   
    } Line;
    
      /* t_location.h */
    typedef struct {      /* probably you need      typedef struct t_location {   ??? */
    	int hash_pos;
    	int num_lines;
    	Line* *lines;
    } t_location;

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    6
    Thanks ^^ that got me rid of most errors.

    I did that, plus changed every piece of code in line.h and t_location.h:
    "Line" => "struct Line"
    "t_location" => "struct t_location"

    But I'm still getting strange stuff:
    Code:
    In file included from line.h:8,
                      gamearea.h:8
                      main.h:12
                      main.c:1
    t_location.h:15: error: expected ')' before '*' token
    make: *** [main.o] Error 1
    t_location.h:15:
    Code:
    t_location* createTLocation(GameArea *gameArea, tetromino *t);
    It is including gamearea.h and tetromino.h before that line.

    Still don't get the problem :\

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    I think it's because definition of Line is not known yet if you include "t_location.h"' at line.h.

    common.h
    Code:
    typedef struct Line Line;   /* struct forward declaration */
    line.h
    Code:
    #include "common.h"
    
    struct Line {
      /* line stuff */
    };
    t_location.h

    Code:
    #include "common.h"
    
    typedef struct {     
    	int hash_pos;
    	int num_lines;
    	Line* *lines;
    } t_location;

  5. #5
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    I did that, plus changed every piece of code in line.h and t_location.h:
    "Line" => "struct Line"
    "t_location" => "struct t_location"
    It's not necessary. What are typedefs for then!

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    6
    Hey thanks for the fast replies, they pointed me to a solution

    The code still doesn't compile with only those modifications. What I did was move every structure declaration to common.h file.
    Code:
    typedef struct X { [attributes]* } X;
    Although I don't like the structure of the code with this modification, it was the only way I got it to compile.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Replies: 6
    Last Post: 04-02-2002, 04:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21