C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-05-2008, 09:14 AM   #1
Registered User
 
Join Date: Jan 2008
Posts: 538
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?
-EquinoX- is offline   Reply With Quote
Old 11-05-2008, 09:23 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 11-05-2008, 10:16 AM   #3
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
So how is that struct declared in the tree.h file? The compiler thinks you are declaring it in the function parameter list.
itCbitC is offline   Reply With Quote
Old 11-05-2008, 01:19 PM   #4
Registered User
 
Join Date: Jan 2008
Posts: 538
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*/

	
};
-EquinoX- is offline   Reply With Quote
Old 11-05-2008, 01:22 PM   #5
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
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.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 11-05-2008, 01:25 PM   #6
Registered User
 
Join Date: Jan 2008
Posts: 538
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
-EquinoX- is offline   Reply With Quote
Old 11-05-2008, 01:27 PM   #7
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Are you a C+ dev?
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 11-05-2008, 01:29 PM   #8
Registered User
 
Join Date: Jan 2008
Posts: 538
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?
-EquinoX- is offline   Reply With Quote
Old 11-05-2008, 01:29 PM   #9
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
Because structs cannot contain functions...
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 11-05-2008, 01:31 PM   #10
Registered User
 
Join Date: Jan 2008
Posts: 538
so how would you translate such thing to C? are you trying to say the reverse? functions cannot contain struct as arguments?
-EquinoX- is offline   Reply With Quote
Old 11-05-2008, 01:31 PM   #11
Banned
 
master5001's Avatar
 
Join Date: Aug 2001
Location: Visalia, CA, USA
Posts: 3,699
Use g++. Or fix this and make it C code.
master5001 is offline   Reply With Quote
Old 11-05-2008, 01:32 PM   #12
Banned
 
master5001's Avatar
 
Join Date: Aug 2001
Location: Visalia, CA, USA
Posts: 3,699
Declare that function outside the struct.
master5001 is offline   Reply With Quote
Old 11-05-2008, 01:32 PM   #13
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
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-
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 11-05-2008, 01:36 PM   #14
Registered User
 
Join Date: Jan 2008
Posts: 538
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?
-EquinoX- is offline   Reply With Quote
Old 11-05-2008, 01:39 PM   #15
Banned
 
master5001's Avatar
 
Join Date: Aug 2001
Location: Visalia, CA, USA
Posts: 3,699
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.
master5001 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22