Thread: how do you resolve this error?

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    how do you resolve this error?

    warning: âstruct ExprNodeâ declared inside parameter list
    util.c:10: warning: its scope is only this definition or declaration, which is probably not what you want


    I have something like this:

    Code:
    void print(struct ExprNode *root, int nLevel){
    
    ............
    ........
    
    }
    and struct ExprNode is on another file called tree.h and I have included that file in my .h file, but why this weird error? how to fix it?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sounds like you have a typo - or you are using C++, so you shouldn't have "struct" in the function definition, perhaps?

    Alternatively, there may be macros at play.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    So how is that struct declared in the tree.h file? The compiler thinks you are declaring it in the function parameter list.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    here's the struct located in the tree.h file:

    Code:
    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*/
    
    	
    };

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    What are the first 10 lines of util.c

    Do you include tree.h ?

    Does tree.h have #ifndef GUARD #endif constructs?

    Are those constructs unique to every single include file, or did you just copy/paste them?

    Oh, and you're writing C++ at this point.
    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.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    Do you include tree.h ?

    Does tree.h have #ifndef GUARD #endif constructs?

    yes it does

    and I don't understand what you mean by those contructs unique to every single include file

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Are you a C+ dev?
    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.

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I am actually a C programmer, and not familiar at all with C++.. I just need to fix this code somehow.. can you guys tell me why it's a C++ program? maybe it's because I am compiling it with gcc that's why it's complaining?

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Because structs cannot contain functions...
    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. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so how would you translate such thing to C? are you trying to say the reverse? functions cannot contain struct as arguments?

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Use g++. Or fix this and make it C code.

  12. #12
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Declare that function outside the struct.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by master5001 View Post
    Use g++. Or fix this and make it C code.
    Then it would be C+ code
    There are trickeries and hacks that can make it possible, but otherwise than that, there is no solution because C is a procedural language. What you are looking at is OOP. C++, Java, C#, etc-
    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.

  14. #14
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    okay lets just fix this code then.. do you compile a C++ file the same as a C file? using gcc -o util.o util.c , something like that?

  15. #15
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by Elysia View Post
    Then it would be C+ code
    There are trickeries and hacks that can make it possible, but otherwise than that, there is no solution because C is a procedural language. What you are looking at is OOP. C++, Java, C#, etc-
    I love my C+ code. Besides, he is copying from a C++ program and trying to integrate code into his C code. I am just trying to make life easier. But she is right... Do a half-assed job and expect half-assed results.

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