![]() |
| | #1 |
| Registered User Join Date: Jan 2008
Posts: 538
| how do you resolve this error? 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){
............
........
}
|
| -EquinoX- is offline | |
| | #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 | |
| | #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 | |
| | #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 | |
| | #5 |
| and the hat of vanishing 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 | |
| | #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 | |
| | #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:
| |
| Elysia is offline | |
| | #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 | |
| | #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:
| |
| Elysia is offline | |
| | #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 | |
| | #11 |
| Banned Join Date: Aug 2001 Location: Visalia, CA, USA
Posts: 3,699
| Use g++. Or fix this and make it C code. |
| master5001 is offline | |
| | #12 |
| Banned Join Date: Aug 2001 Location: Visalia, CA, USA
Posts: 3,699
| Declare that function outside the struct. |
| master5001 is offline | |
| | #13 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| 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:
| |
| Elysia is offline | |
| | #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 | |
| | #15 |
| Banned Join Date: Aug 2001 Location: Visalia, CA, USA
Posts: 3,699
| 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |