Skip to main content
GameDev.net gamedev.net
🔒 Locked

Strange #include problem

Started by BrknPhoenix Jul 6, 2006 at 9:19 PM 6 replies 1k views
Original Post
BrknPhoenix
BrknPhoenix
The problem in question is one related to turning a part of my program into an object. I finally got glFont to work with some sloppy quick procedural code, so as usual I'm now making everything neat and nice and putting it in a class. However, a strange problem has arisen. This error: expected init-declarator before ';' token and expected ',' or ';' before '*' token Here's the file that the error is showing up in:

#ifndef GLOBALS__H
#define GLOBALS__H

#include <allegro.h>
#include <alleggl.h>

#include "camera.h"
#include "debug.h"
#include "draw.h"
#include "gamemanager.h"
#include "gfx.h"
#include "logic.h"
#include "mouse.h"
#include "screen.h"
#include "text.h"

#include "glfont2.h"
using namespace glfont;

extern volatile unsigned int timer;

extern                  objCamera*       Camera;
extern                  objDebug*        Debug;
extern                  objDraw*         Draw;
extern                  objGameManager*  GameManager;
extern                  objGfx*          Gfx;
extern                  objLogic*        Logic;
extern                  objMouse*        Mouse;
extern                  objScreen*       Screen;
extern                  objText*         Text;

extern const char*      MOUSE_SPRITE;
extern const char*      MOUSE_MASK;
extern const char*      TITLE_HEADING;
extern const char*      TITLE_HEADING_M;
extern const char*      TITLE_BACKGROUND;

extern GLuint           texHeading;
extern GLuint           texHeading_m;
extern GLuint           texTitleBackground;

extern GLFont           testFont;
extern GLuint           texTestFont;

#endif
and here is the header that broke it

#ifndef TEXT__H
#define TEXT__H

#include <allegro.h>
#include <alleggl.h>
#include <string>
#include <utility>

#include "defines.h"
#include "globals.h"

#include "glfont2.h"
using namespace glfont;

class objText
{
    private:
    public:
             objText();
            ~objText();
        void Out(char*, GLFont, float, float, float, int);
};

#endif
Prior to the line #include "text.h" being added into the first file, everything compiled flawlessly. Trying to add the objText header broke it... Somehow. Keep in mind that this worked when I did it procedurally. The extern objText* Text; business was there when it worked. It was the specific act of adding that #include
jflanglois
jflanglois
Which line does the error point you to?
[edit: I suspect it is in glfont2.h. Note that using namespace in headers is bad karma. ]
[edit2: Note also that you have circular inclusion. text.h includes globals.h and globals.h include text.h. Choose one or the other, but not both. ]
BrknPhoenix
BrknPhoenix
Quote:
Original post by jflanglois
Which line does the error point you to?


extern objText* Text;

The thing is, this was there before and it worked. When I usually get this error, it means I didn't included the objects header, and it's solved by including the header. So this is an error I should get if i DIDN'T include text.h... But changing to this format and #including text.h all of a sudden makes it not work.

The error tells me it doesn't know what objText is, but I included the header sooooo... I dunno
jflanglois
jflanglois
Remove #include "globals.h" from text.h.
BrknPhoenix
BrknPhoenix
Quote:
Original post by jflanglois
Remove #include "globals.h" from text.h.


Interesting, it worked... But why?
jflanglois
jflanglois
Which compiler is this? As I said in my second edit, you had a circular include. I suppose that it's possible that the compiler, instead of complaining about it, stopped including after a set amount of times and had the contents of globals.h first, at which point objText was not declared.

Hint: if your compiler allows you to just do the preprocessor pass, choose that and look at the output.

[Edited by - jflanglois on July 6, 2006 10:30:46 PM]
BrknPhoenix
BrknPhoenix
Quote:
Original post by jflanglois
Which compiler is this? As I said in my second edit, you had a circular include. I suppose that it's possible that the compiler, instead of complaining about it, stopped including after a set amount of times and had the contents of globals.h first, at which point objText was not defined.


g++

And I realized previously that the includes were circular, but I didn't think that was a problem because I've been doing that the entire program, lol. I've pretty much just put globals and defines.h in every file, and I hadn't had any problems until this object.
jflanglois
jflanglois
Interesting, I would have expected VC8 to complain about circular inclusion, but it does the same as GCC 3.2.3.

Anyway, I stand by my explanation:

global.h:
#ifndef GLOBAL_H#define GLOBAL_H#include "test.h"extern Test *test;#endif

test.h:
#ifndef TEST_H#define TEST_H#include "global.h"struct Test {	void Do();};#endif

test.cpp:
#include "test.h" // If you change this to globals.h, it compiles fine, since it includes test.h "before" global.h ("after" recursively)void Test::Do() {}int main() {}

[edit: Result of cpp test.cc (C Preprocessor):
# 1 "test.cc"# 1 "<built-in>"# 1 "<command line>"# 1 "test.cc"# 1 "test.h" 1# 1 "glob.h" 1# 1 "test.h" 1# 5 "glob.h" 2<font color="red">Test is not yet declared</font>extern Test * test;# 5 "test.h" 2<font color="red">Test is defined here, after the pointer</font>struct Test {  void Do();};# 2 "test.cc" 2void Test::Do() {}int main() {}
]

The moral of the story: only include what is necessary for a particular translation unit.


jfl.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.