0

I am currently writing a token recognizer for XML. I am going along the basis of FSA's to do so. So I have a Header file that has the following code...

#define MAX_LENGTH    512
#define  MAX_NAME  25

struct token 
{
  char name[MAX_NAME + 1];
  int type;
  unsigned char str[MAX_LENGTH + 1];
 };

 #define TOKEN_TYPES 8

 #define SPACES  0
 #define NEWLINE  1
 #define WORD  2
 #define BEGINTAG  3
 #define ENDTAG  4
 #define EMPTYTAG 5
 #define ERROR 6
 #define ENDFILE 7

With this I am getting the error:

error C2011: 'token' : 'struct' type redefinition

I am also getting another strange error in my gettoken.cpp file. Where I actually implement the FSA. The File is far to long to display the entire contents. But with this I am getting the error...

error C1014: too many include files : depth = 1024

And here is part of the code for that .cpp file. I will only include my imports in this.

#include  <iostream>
#include  <fstream>
#include  <stdlib.h>
#include  <string>
#include  "Token.h"

using namespace std;

I am sure it is something silly as it usually is for me. But please help me out! Thanks!

2
  • have you added include guards to your headers?
    – George
    Nov 5, 2010 at 1:59
  • 1
    Any reason you're not just using std::string? And an enum? Or constants instead of #define's at the least.
    – GManNickG
    Nov 5, 2010 at 2:02

3 Answers 3

3

I assume you're somehow including your header file twice. Do you have a guard against that? Every header file should have this:

#ifndef TOKEN_H
#define TOKEN_H

[your header file code]

#endif

If that's not it, make sure you're not defining token twice somewhere else.

1
  • wow I'm such an idiot. I had my include guards but when I copied and pasted into Visual Studio I left them out by accident! Thanks!
    – Johnrad
    Nov 5, 2010 at 2:01
1

You are probably missing the include guards and getting into include file recursion.

1

Add this line to every header file:

#pragma once
4
  • Why add a non-standard line to every header file?
    – GManNickG
    Nov 5, 2010 at 2:09
  • Why add random strings repeated in 3 lines to every header file? You call it non-standard, but every compiler supports it fine.
    – Blindy
    Nov 5, 2010 at 2:14
  • 1
    It's still non-standard. (Not that that matters to a lot of people)
    – EboMike
    Nov 5, 2010 at 2:17
  • Not to mention that pragma once increases compilation speed, which is pretty important when it already takes hours to compiler large projects.
    – Blindy
    Nov 5, 2010 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.