# Where are these parse errors coming from?

This topic is 4482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey there, this is my first post. I hope it's in the right place. :) I'm currently working on my first SDL game with xCode, and It's quite nearly done. It just needs 4 or 5 lines of code and it's done! Hurray! Well, not quite, I just finished my collision system and I'm getting some of those horrible parse errors. (Don't ya just hate them? It's like saying: "There's an error somewhere else. Find it.") Anyway, I'm completely 100% stumped, it looks all good for me, but first, the one error that is *not* a parse problem (7 of them are, 2 aren't). collision.c:60: error: redefinition of 'p' This is in association with this little block of code: if (o == pixelSurface_2->h) { o++; // Next collumn. p = 1; // First item of that row of the next collumn. } collision.c:46: error: previous definition of 'p' was here int p = 1; p is modified between those two blocks of code. Now, I've done this before in my code, and no errors, so why the heck am I getting one here? Now, my other errors are: collision.c:25: error: parse error before ')' token collision.c:41: error: parse error before '}' token collision.c:50: error: parse error before "for" collision.c:55: error: parse error before '.' token collision.c:56: error: parse error before '.' token collision.c:61: error: parse error before '}' token main.c:16: error: parse error before numeric constant I guess this is no good to you guys without the source. The three source files are here: http://homepage.mac.com/gareth.cross/fixme/main.c http://homepage.mac.com/gareth.cross/fixme/collision.c http://homepage.mac.com/gareth.cross/fixme/collision.h The entire project is available for download here: http://homepage.mac.com/gareth.cross/fixme/SDLapp.zip I know this is asking a lot of you guys, but I'm really stumped, and not really sure where to turn to. I'd rather solve this myself too, but I have no idea how. Thanks a tonne for any help you guys would be willing to offer!

##### Share on other sites
They syntax for your for loops is incorrect.

collision.c line 25:
for (i < pixelSurface_1->w) {

should be either:
for (; i < pixelSurface_1->w;) {

or:
while (i < pixelSurface_1->w) {

##### Share on other sites
Also, on line 16 in main.c, you're calling SDL_ShowCursor outside of any function, which is incorrect.

##### Share on other sites
Hi,

- You put too much comments (where we dont need them)
- You "should" always put variables at the beginning of a method
- And last, you are using java coding style (which i personnaly hate, but this is your call ;))

Second, forget it, someone already found the error so give it a try and if this is not solving your problem post again...

Anyhow, best luck with your game.
Jonathan

##### Share on other sites
When you get a whole bunch of parse errors like that, it's usually good to try to fix the first one first. One missing parenthesis, bracket, or semicolon will often cause errors throughout the rest of the file.

##### Share on other sites
Quote:
 Original post by KrazeIkeThey syntax for your for loops is incorrect.collision.c line 25:for (i < pixelSurface_1->w) {should be either:for (; i < pixelSurface_1->w;) {or:while (i < pixelSurface_1->w) {

Your joking... you mean I was missing something that silly all along? *smashes head against wall*

And I was trying to treat SDL_ShowCursor like a GLUT setup aspect, as that's what I learned first. Another of my incredibly stupid mistakes. :(

*sigh*

Thanks guys!

EDIT: Nevermind... look down.

[Edited by - OneMoreToGo on May 8, 2006 11:36:22 PM]

##### Share on other sites
Well... it went from 9 errors, to 1 to 7.

I fixed everything except the SDL cursor command, which returned one error. So I chucked it into my main function and got 7 errors. So I deleted it entirely and I still have 7 errors. One indicating that SDL has magically changed in the short time it's been on my hard drive, 4 that are telling me that variables that clearly exist - don't, and finally, two parse errors.

I tried cleaning all my targets and re-building them, but no luck. The new source is the same as before, except I took out the cursor command and fixed the for loops.

Here are the errros:

collision.c:4: error: parse error before '*' token
Um... ok, but there's nothing before that line of code that could be an error...

collision.c:10: error: 'pixelSurface_1' undeclared (first use in this function) (Each undeclared identifier is reported only once for each function it appears in.)
But it has been...

collision.c:11: error: 'pixelSurface_2' undeclared (first use in this function)
Once again, it has...

collision.c:14: error: 'SDL_Rect' undeclared (first use in this function)
Ok, SDL no longer has that command. I'll make sure to check for little green goblins in my computer removing functions from my frameworks. ;)

And so on and so forth with the following:

collision.c:14: error: parse error before "surfaceRect1"
collision.c:29: warning: implicit declaration of function 'SDL_GetClipRect'
collision.c:29: error: 'surfaceRect1' undeclared (first use in this function)
collision.c:54: error: 'surfaceRect2' undeclared (first use in this function)
collision.c:11: warning: unused variable 'pixelData_surface2'
collision.c:10: warning: unused variable 'pixelData_surface1'

I'll bet it's just one error that happens to make the compiler trip over itself and produce many. Note: All those errors above are incorrect. All the "unused variables" are used, and all the "undeclared stuff" is declared.

But I swear, my wall will have a large dent in it if this continues.

##### Share on other sites
That first error is there because you haven't included the SDL header files in collision.c. Another thing I noticed is that you're including collision.c in main.c. You probably shouldn't do that. Normally, you only include header files, not source files.

##### Share on other sites
Quote:
 Original post by KrazeIkeThat first error is there because you haven't included the SDL header files in collision.c. Another thing I noticed is that you're including collision.c in main.c. You probably shouldn't do that. Normally, you only include header files, not source files.

But my structs have to be in my headers, and my funcs have to be in my c files, right?

EDIT: Dit it, and.... christ that was all I needed? I'm down to *one* error now! I thought you were only allowed to include .h files *once* per program...

##### Share on other sites
Quote:
 Original post by OneMoreToGoBut my structs have to be in my headers, and my funcs have to be in my c files, right?

Well, yes and no. You declare stuff in the header file and define stuff in the c file.

//declaration, belongs in .h
void Draw();

//definition, belongs in .c
void Draw()
{
}

//declaration
class Vector
{
void Normalize();
};

//definition
void Vector::Normalize()
{
}

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5

• 14
• 13
• 14
• 75
• 22
• ### Forum Statistics

• Total Topics
632145
• Total Posts
3004341

×