DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 28

Thread: Unexpected End of File

  1. #1
    Join Date
    Aug 2003
    Posts
    313

    Unexpected End of File

    Hey, I'm working on an interpreter and I keep getting errors saying:
    C1004 Unexpected end of file.

    Does anyone have any idea what this means? I've read various things saying that its looking for close parenthesis or something like that, but I've looked over it several times and haven't found anything. Any help would be greatly appreciated. Thanks a lot.
    Attached Files Attached Files
    ~evlich

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    I note that ashvisitor and ash include each other -- this could be a problem.

  3. #3
    Join Date
    Aug 2003
    Posts
    313
    Shouldn't the #ifndef's handle this?
    ~evlich

  4. #4
    Join Date
    Nov 2003
    Posts
    4,118
    you're using the ideitifier AST both a class name and a namespace. This is certainly not going to work, althopugh there are probably other problems in the code.
    Danny Kalev

  5. #5
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    Quote Originally Posted by evlich
    Shouldn't the #ifndef's handle this?
    #ifndef will stop a header read knowledge from other.
    its only for avoiding redeclarations.
    AST class dont need a complete ASTVisitor declaration.
    ( pointer or reference with forward declaration)
    if AST realy needed ASTVisitor header ,#ifndef wouldnt help ( depending #include order. )
    same for other header files in AST.h ( if they include ASTVisitor.h ) becos AST visitor seems "known" but has not been red yet)
    why you add a "header" end of a file
    insteed of adding them to other cpp or header files when required ?

  6. #6
    Join Date
    Dec 2003
    Posts
    3,366
    I cant tell you how it all works, but I can tell you that include guards are not always going to work here. We did this accidentally last project, and as was mentioned, a forward decl fixed our problems and the circular includes were avoided. Our stuff had include guards but would not compile, I forget what errors it 'created' to explain its problems.

  7. #7
    Join Date
    Nov 2003
    Posts
    4,118
    circular references of classes are solved by using a forward declaration of one class in the other. This is a bit restricting because you can't call a member function of a forward declared class but you can use it as an argument (passed by reference) in the other class, which is what you really need. Make sure that each class has its own .cxx file which includes *only* its matching .h file and perhaps the headers that contain constants and other shared declarations. Don't #include a.h in b.cpp if a defined a.cpp.
    Danny Kalev

  8. #8
    Join Date
    Nov 2003
    Posts
    4,118
    Eureka! your project probably uses the infamous "precompiled headers" option. Disable it, and remove the "stdafx.h" header from it.
    Danny Kalev

  9. #9
    Join Date
    Aug 2003
    Posts
    313
    My implementation of BoolConstant requires knowledge of methods in ASTVisitor, so if I remove my include of ASTVisitor.h from AST.h and put it in BooleanConstant.cxx, then I guess I should be ok right? I also removed the old "using namespace AST" which I guess I had missed.

    I checked the thing with the pre-compiled headers and I have "Create/Use Precompiled Header" on the option saying "Not Using Precompiled Headers". Also, I'm never including stdafx.h anywhere, is it automatically included some way in VS2003?
    Unfortunately, even after these modifications, I'm still getting the error. Any other ideas? Thanks.
    ~evlich

  10. #10
    Join Date
    Nov 2003
    Posts
    4,118
    Check for unblanaced #ifndef and #endif pais in all your header files. Also, try to see what happens when you remove these directives althogether. Finally, try to collapse the two class headers into one header file. Decalre both classes in it and see if this solves the problem. Later you can split it again.
    Danny Kalev

  11. #11
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    still some confusing dependicies forexample:
    booleanConstant: public AST
    booleanConstant designed after AST designed.
    but AST.h includes( needs to know ) booleanConstant.h
    ....
    i dont know if i miss something :
    -AST needs a forward Declare to ASTVisitor , don't need ASTVisitor.h or booleanConstant.h
    -ASTVisitor.h needs AST.h
    -booleanConstant.h needs only ASTVisitor.h


    Danny's advices about #include logic were perfect.
    Quote Originally Posted by Danny
    Don't #include a.h in b.cpp if a defined a.cpp.
    Last edited by mr1yh1; 11-20-2005 at 07:56 AM. Reason: my poor english :)

  12. #12
    Join Date
    Aug 2003
    Posts
    313
    Ok, I tried combining all the files into a single .h file and it worked. Then I split them apart without the #ifndef ... #endif stuff and it worked, but as soon as I put the #ifndef stuff in, it fails. I put in #error directives in else clauses to check to see if something was being included twice, but none of them are. My files are:
    AST.h
    Code:
    #ifndef __AST_H__
    #define __AST_H__
    
    class ASTVisitor;
    
    class AST {
    public:
    	virtual void process(ASTVisitor &visitor) = 0;
    };
    #else
    #error FAIL
    
    #endif
    ASTVisitor.h
    Code:
    #ifndef __AST_VISITOR_H__
    #define __AST_VISITOR_H__
    class BooleanConstant;
    
    class ASTVisitor {
    protected:
    	ASTVisitor();
    
    public:
    	/** Constant Constructions **/
    	virtual void forBooleanConstant(BooleanConstant *boolConst) = 0;
    };
    
    #else
    #error FAIL
    #endif
    BooleanConstant.h (it turns out that I have to include AST.h in this file otherwise the compiler complains that it doesn't know about the base class AST even when I just put a forward declaration)
    Code:
    #ifndef __BOOLEAN_CONSTANT_H__
    #define __BOOLEAN_CONSTANT_H__
    
    #include "AST.h"
    
    class BooleanConstant : public AST {
    private:
    	bool _value;
    	static BooleanConstant _TRUE;
    	static BooleanConstant _FALSE;
    
    public:
    	bool getValue();
    	virtual void process(ASTVisitor &visitor);
    
    protected:
    	BooleanConstant(bool value);
    	virtual ~BooleanConstant();
    public:
    	static const BooleanConstant* forValue(bool b);
    };
    
    #else
    #error FAIL
    #endif
    And BooleanConstant.cxx
    Code:
    #include "BooleanConstant.h"
    #include "ASTVisitor.h"
    
    BooleanConstant::BooleanConstant(bool b) {
    	_value = b;
    }
    
    BooleanConstant::~BooleanConstant() {
    }
    
    void BooleanConstant::process(ASTVisitor &visitor) {
    	visitor.forBooleanConstant(this);
    }
    
    const BooleanConstant* BooleanConstant::forValue(bool b) {
    	if( b ) {
    		return &BooleanConstant::_TRUE;
    	} else {
    		return &BooleanConstant::_FALSE;
    	}
    }
    Any ideas as to why this might happen? Thanks a lot for all your help.
    Last edited by evlich; 11-20-2005 at 02:59 PM.
    ~evlich

  13. #13
    Join Date
    Nov 2003
    Posts
    4,118
    Two more options to check are order dependecies, i.e, which header should be #included before which. Don't #include a header inside another header, this could lead to a total mess. Remember: a header doesn't have to compile by itself; it is always part of a larget translation unit.
    Danny Kalev

  14. #14
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    Code:
    ///AST.h
    #ifndef __AST_H__
    #define __AST_H__
    
    class ASTVisitor;
    
    class AST {
    ...
    Code:
    ///ASTVisitor.h
    #ifndef __AST_VISITOR_H__
    #define __AST_VISITOR_H__
    
    #include "AST.h"
    class BooleanConstant;
    
    class ASTVisitor {
    ...
    Code:
    ///booleanConstant.h
    #ifndef __BOOLEAN_CONSTANT_H__
    #define __BOOLEAN_CONSTANT_H__
    
    #include "ASTVisitor.h"
    
    class BooleanConstant : public AST {
    ...
    Code:
    ///BooleanConstant.cpp
    #include "BooleanConstant.h"
    
    BooleanConstant::BooleanConstant(bool b) {
    _value = b;
    }
    ...
    gcc did compile this.
    only 2 linking problems undefined reference to `BooleanConstant::_TRUE'
    ...

  15. #15
    Join Date
    Aug 2003
    Posts
    313
    So, I guess that means this is a problem with VS2003. Has anyone run into something like this before? My guess is that I probably have a compiler option set wrong, but I have no idea where to look.
    ~evlich

Similar Threads

  1. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 12:18 PM
  2. How to save changes to a msflexgrid
    By Tommy in forum VB Classic
    Replies: 0
    Last Post: 06-23-2002, 03:15 PM
  3. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  4. NT Authentication within VB app
    By Amy in forum VB Classic
    Replies: 10
    Last Post: 12-21-2000, 12:21 AM
  5. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 2
    Last Post: 08-11-2000, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center