Skip to main content
gamedev.net
🔒 Locked

linked list in c problem

Started by PrettySneaky Jun 9, 2004 at 7:36 AM 13 replies 950+ views
Original Post
PrettySneaky
PrettySneaky
I have just copy pasted this piece of code from one project to another.

typedef struct _BoundingVolume
{
	ExpandedVolume encloseVolume;
	
	Geometry *geom;
    
	_BoundingVolume	*leftChild;
	
	_BoundingVolume	*rightChild;

	Vec3f	h;

} BoundingVolume;

But VS .NET doesn't whant to compile it? I can't understand why because I have wrote and used this data type on a different program. I get this error message: error C2061: syntax error : identifier '_BoundingVolume' [edited by - SiCrane on June 9, 2004 5:34:11 PM]
evolutional
evolutional
Have the other types you used been declared?

P.S. Generally ''bad'' language isn''t considered appropriate in the forums outside of the L*unge.
snk_kid
snk_kid
Nothing wrong with that make sure your including the declartion of the types before _BoundingVolume.
PrettySneaky
PrettySneaky

Sorry about the bad language. This #¤%&#¤%& code just drives me insane.

I have defined the other datatypes above _BoundingVolume in my header.

AND, the code have worked on other projekt.. :[

Bah!
PrettySneaky
PrettySneaky
Ok!

I tried to an extremely simple linked list



typedef struct _ll
{
_ll *next;
int i;
} LL;



Still the same error message.. THIS SHOULD work. What the hell is wrong with my compiler. It do work if i start a new project and just define this single datatype och and declare it in the main func.. ??!?!
Namethatnobodyelsetook
Namethatnobodyelsetook
Perhaps the thing immediately before it is missing a semicolon, or missing a closing brace. Usually errors that make no sense are because of a problem immediately above.

Another unlikely possibility is that you''ve #defined typedef or struct.
PrettySneaky
PrettySneaky

Doesn''t seem to be that. I defined the struct in several different files and compiled... Same error

And I have not define struct of typedef..

Ahh..
pTymN
pTymN
try this:

typedef struct STRUCTNAME_BLAH {
float x, y;
};


STRUCTNAME_BLAH myInstance;


I think that if you are using typedef, that you don''t want to have the variable declared in the same statement. I don''t remember exactly, but i''ve had the same problem before and did something similar to what i stated to fix it.
 
Paradigm Shifter
Paradigm Shifter


typedef struct _ll
{
struct _ll *next;
int i;
} LL;



You need to use the non-typedef''d struct name if you want to have a pointer to its own type, with the word struct before it too.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
PrettySneaky
PrettySneaky

Yes!! Thanx!

I guess the reason that my code didn''t work was because that it is a pure c program. My old program that i ripped the code from whas a c++ program without OO.
Paradigm Shifter
Paradigm Shifter
No problemo. Now wash your mouth out with soap!



"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
OOCCO
OOCCO
Surely it should be



typedef struct _ll
{
LL *next;
int i;
} LL;

"The Holocaust was an obscene period in our nation's history. I mean in this century's history. But we all lived in this century. I didn't live in this century."...Governor George W. Bush, 9/15/95
quorn
quorn
You can change the title of your message by editing the original post. Maybe call it something like "C - problem declaring struct with pointers of own type as members". It does away with the expletive and is also a far better description of the problem.
Paradigm Shifter
Paradigm Shifter
quote:
Original post by OOCCO
Surely it should be



typedef struct _ll
{
LL *next;
int i;
} LL;




That doesn''t work in ANSI C. The typedef name hasn''t been parsed by the time it sees the LL* declaration.



"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.