Thread: how do you resolve this error?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    To compile as C++, I believe you need to use g++.
    I really have no problems with you trying to extend C beyond what it was designed for, but I think at some point you really should decide to go C or C++, since they are two different beasts and people will likely frown at such a mix, not to mention you would probably not get away with it in a job.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so something like g++ -g util.o util.c would work?

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > and I don't understand what you mean by those contructs unique to every single include file
    Well tree.h might be
    #ifndef TREE_H_INCLUDED
    #define TREE_H_INCLUDED
    // some stuff
    #endif



    But if some other file (say util.h), also has (by some mistake)
    #ifndef TREE_H_INCLUDED
    #define TREE_H_INCLUDED
    // some stuff
    #endif

    Then including util.h before tree.h will make everything in tree.h invisible.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by -EquinoX- View Post
    so something like g++ -g util.o util.c would work?
    Eh, no idea, I do not compile manually. Someone else will peek into your problem in due time, I guess, and provide you an answer.
    Cannot be of help there. Sorry.
    But you can always try.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    well, here's tree.h if you want to see it:

    Code:
    #ifndef tree_h
    #define tree_h
    
    typedef enum{
    	T_EXPR_INTCON,
    	T_EXPR_STRINGCON,
    	T_EXPR_CHARCON,//
    
    	T_EXPR_VARIABLE,
    	T_EXPR_ARRAY,
    	T_EXPR_FUNCALL,
    
    	T_EXPR_ADD,
    	T_EXPR_SUB,
    	T_EXPR_MUL,
    	T_EXPR_DIV,
    	T_EXPR_UMINUS,
    
    	T_EXPR_REOP_GT,
    	T_EXPR_REOP_LT,
    	T_EXPR_REOP_LE,
    	T_EXPR_REOP_GE,
    	T_EXPR_REOP_NE,
    	T_EXPR_REOP_EQ,
    
    	T_EXPR_NOT,
    	T_EXPR_AND,
    	T_EXPR_OR,
    
    	//T_FUNCAL_ENTRY,//could be in expr, also could be in stamtment
    
    	T_TYPE_INT,
    	T_TYPE_ARRAY_INT,
    	T_TYPE_CHAR,
    	T_TYPE_ARRAY_CHAR,
    	T_TYPE_VOID,// an fun could has no return, thus has void, it is necessary to check error, like a+f(b), but f has no return,
    	T_TYPE_BOOL,
    	T_TYPE_STRINGCON,
    	T_EXTERN,
    
    	T_NOT_FOUND,//return when look up a variables not found,
    
    
    	T_STMT_IF,
    	T_STMT_IFELSE,
    	T_STMT_WHILE,
    	T_STMT_FOR,
    	T_STMT_RETURN,
    	T_STMT_FUNCALL,
    	T_STMT_ASSIGN_VAR,
    	T_STMT_ASSIGN_ARRAY,
    
    
    	// include the array,
    	// to think, if it is array, it should have a
    	// arrayExp point to an Integer constant
    	T_DCL_VAR_INT,
    	T_DCL_VAR_CHAR,
    
    	T_DCL_ARRAY_INT,
    	T_DCL_ARRAY_CHAR,
    
    	T_DCL_ARRAYLEN,
    
    	T_DCL_EXTERN_VAR_INT,
    	T_DCL_EXTERN_VAR_CHAR,
    
    	T_DCL_EXTERN_ARRAY_INT,
    	T_DCL_EXTERN_ARRAY_CHAR,
    
    
    	T_DCL_FUN_VOID,
    	T_DCL_FUN_INT,
    	T_DCL_FUN_CHAR,
    	T_DCL_FUN_STRING,
    
    
    	T_DCL_FUN_EXTERN_VOID,
    	T_DCL_FUN_EXTERN_INT,
    	T_DCL_FUN_EXTERN_CHAR,
    
    	T_FUN_BODY_INT,//used
    	T_FUN_BODY_CHAR,//used
    	T_FUN_BODY_VOID,//used
    
    	T_PARAM_VAR_INT,
    	T_PARAM_VAR_CHAR,
    	T_PARAM_ARRAY_INT,
    	T_PARAM_ARRAY_CHAR,
    	T_PARAM_VOID,
    
    	T_SYM_INT,
    	T_SYM_CHAR,
    	T_SYM_VOID
    
    
    	} ExprType;
    
    
    struct ExprNode {
    	ExprType type;
    	
    	struct ExprNode *next;//used for parameter exprList r;
    	struct ExprNode *prior;//used for  parameter list
    
    
    	struct ExprNode *parent;//or the son exp
    	struct ExprNode *left; //used for any expression element, array,
    	struct ExprNode *right;
    
    	struct ExprNode *StmtDomain[4];
    	
    	//it is used for statment and function body
    
    	
    	char* name;// name for function and Identfier
    	
    	int n;
    	
    	int nodeSeen;
    	int tempVarCount;
    	int rootLabelCount;
    	
    	
    	/*static void print(ExprNode *p,int n);
    	static void printTab(int n);//print n tabs*/
    
    	
    };
    
    
    #endif

  6. #21
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    here's util.h

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include "tree.h"
    #include "threeaddress.h"
    
    void printTab(int );
    void print(struct ExprNode *, int );
    and part of util.c:

    Code:
    void printTab(int n)
    {
    	int i;
    	for(i=0;i<n;i++)
    	{
    		printf("\t");
    	}
    	printf("&#37;d:",n);
    }
    
    void print(struct ExprNode *root, int nLevel)
    {
    	printTab(nLevel);
    	if(root==NULL) {printf("NULL\n"); return;}
    	switch (root->type)
    	{
    		case T_EXPR_INTCON:
    			printf("%d\n",root->n);
    			if(root->next!=NULL) print(root->next,nLevel);
    			break;
    		case T_EXPR_STRINGCON:
    			printf("\" %s \"\n",root->name);
    			if(root->next!=NULL) print(root->next,nLevel);
    			break;
    		case T_EXPR_CHARCON://
    			printf("'%c'\n",root->n);
    			if(root->next!=NULL) print(root->next,nLevel);
    			break;
    
    		case T_EXPR_VARIABLE:
    			printf("%s\n",root->name);
    			if(root->next!=NULL) print(root->next,nLevel);
    			break;
    
    		case T_EXPR_ARRAY:
    			printf("%s[]\n",root->name);
    			print(root->left,nLevel+1);
    			break;
    		case T_EXPR_FUNCALL:
    			printf("%s()\n",root->name);
    			print(root->left,nLevel+1);
    			break;
    		case T_EXPR_ADD:
    			printf("+\n");
    			print(root->left,nLevel+1);
    			print(root->right,nLevel+1);
    			break;
    		case T_EXPR_SUB:
    			printf("-\n");
    			print(root->left,nLevel+1);
    			print(root->right,nLevel+1);
    			break;

  7. #22
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by master5001 View Post
    Declare that function outside the struct.
    That devilishly clever dude had a good point. Whoever he is.

  8. #23
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    what do you mean declare the function outside the struct? the struct is taken as an parameter arguments inside the function parameter..

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    struct foo { void foo2(); } // Function declared inside struct
    struct foo3 {};
    void foo2(); // Function declared outside struct
    The first is only valid in C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    Quote Originally Posted by Elysia View Post
    Code:
    struct foo { void foo2(); } // Function declared inside struct
    struct foo3 {};
    void foo2(); // Function declared outside struct
    The first is only valid in C++.
    well that's my point, if that's only valid in C++ then compiling it in C++ would solve my problem away right?

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Indeed it would. I was only pointing out what master5001 was implying.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    well now can someone please help me on how to compile this in C++?? as I tried what I did by replacing gcc with g++ and got errors

  13. #28
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Haven't you been here long enough to realize "got errors" is insufficient???

  14. #29
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    here you go, :

    Code:
    util.cpp:133: error: &#226;T_STMT_FOR&#226; was not declared in this scope
    util.cpp:135: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:136: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:137: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:138: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:139: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:139: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:139: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:141: error: &#226;T_STMT_RETURN&#226; was not declared in this scope
    util.cpp:143: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:144: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:144: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:144: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:146: error: &#226;T_STMT_FUNCALL&#226; was not declared in this scope
    util.cpp:147: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:148: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:149: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:149: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:149: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:151: error: &#226;T_STMT_ASSIGN_VAR&#226; was not declared in this scope
    util.cpp:152: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:153: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:154: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:154: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:154: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:156: error: &#226;T_STMT_ASSIGN_ARRAY&#226; was not declared in this scope
    util.cpp:157: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:158: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:159: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:160: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:160: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:160: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:163: error: &#226;T_DCL_VAR_INT&#226; was not declared in this scope
    util.cpp:164: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:165: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:165: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:165: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:167: error: &#226;T_DCL_VAR_CHAR&#226; was not declared in this scope
    util.cpp:168: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:169: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:169: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:169: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:171: error: &#226;T_DCL_ARRAY_INT&#226; was not declared in this scope
    util.cpp:172: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:172: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:173: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    util.cpp:11: error: forward declaration of &#226;struct ExprNode&#226;
    util.cpp:173: error: &#226;NULL&#226; was not declared in this scope
    util.cpp:173: error: invalid use of incomplete type &#226;struct ExprNode&#226;
    I compiled using

    g++ -c -o util.o util.cpp

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The problem seems to be that you are using ExprNode before it has been defined.
    Did you put a forward declaration somewhere?
    Perhaps you should post the code in the source file up to the first usage of the struct?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM