gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > parse error before '.' token

#33903 - SilentDesign - Tue Jan 11, 2005 12:42 am

Hey fellas'. I'm new to using gcc and am just wondering what might have cause this error in my game? I'm not too sure what this means or how to fix it so if you can help it'll be appreciated thanks.
_________________
"Tis' best to do wrong, then RIGHT!!!"

#33904 - sajiimori - Tue Jan 11, 2005 12:50 am

It's a syntax error. That's about all anybody can tell you unless you post the erroneous portion of your code.

#33906 - SilentDesign - Tue Jan 11, 2005 12:59 am

typedef struct Balls
{
int xVelocity;
int yVelocity;

u8 xMax;//240 - xMin
u8 yMax;//160 - yMin
u8 xMin;
u8 yMin;

u16 xball;//30
u16 yball;//15
}ball;

ball Ball;

Ball.xVelocity = 4;
Ball.yVelocity = 2;

Ball.xMax = 232;
Ball.yMax = 152;
Ball.xMin = 8;
Ball.yMin = 8;

Ball.xball = 30;
Ball.yball = 15;
_________________
"Tis' best to do wrong, then RIGHT!!!"

#33907 - sgeos - Tue Jan 11, 2005 1:13 am

It compiled fine for me. I had to add type definitions for u8 and u16, and put the code into a function to get it to compile.

-Brendan

#33908 - SilentDesign - Tue Jan 11, 2005 1:16 am

hey, what version of gcc are you using?
I'm using the version that comes with devkitadv
_________________
"Tis' best to do wrong, then RIGHT!!!"

#33910 - sgeos - Tue Jan 11, 2005 1:26 am

Code:
$ gcc --version
gcc (GCC) 3.3.3 (cygwin special)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The version doesn't matter. If you write ANSI compliant code, it should compile with any compiler.

-Brendan

#33911 - SilentDesign - Tue Jan 11, 2005 1:34 am

well i dun' know, you say the code worked in your function, why the heck is it not working for me. I read on some site i found off google that those parse errors happened with older gcc versions and not with newer ones
, hmmm..
_________________
"Tis' best to do wrong, then RIGHT!!!"

#33913 - poslundc - Tue Jan 11, 2005 1:46 am

Parse errors happen because of syntax errors in your code, irrespective of what version of GCC you are running. Getting a newer version of GCC will not fix your code.

It is highly irregular to have a struct declaration in such close proximity to executable code. Are you sure you haven't declared a function somewhere?

The compiler should say what line number of what file the error occurred in. That is where you should look.

It's a guess, but based on the type of parse error, I'm guessing you've forgotten a semicolon somewhere.

Dan.

#33939 - phantom-inker - Tue Jan 11, 2005 9:45 am

Er... actually... I'd guess there's no main() function. Unless I miss my guess, the assignments to Ball.whatever are taking place outside any function, which might be legal in Javascript, but is a no-no in C. Try this:

Code:

typedef struct {
  int xVelocity;
  int yVelocity;

  u8 xMax;//240 - xMin
  u8 yMax;//160 - yMin
  u8 xMin;
  u8 yMin;

  u16 xball;//30
  u16 yball;//15
} ball;

ball Ball;

void SetupBall(void)
{
  Ball.xVelocity = 4;
  Ball.yVelocity = 2;

  Ball.xMax = 232;
  Ball.yMax = 152;
  Ball.xMin = 8;
  Ball.yMin = 8;

  Ball.xball = 30;
  Ball.yball = 15;
}


Be sure to call SetupBall() at some point, or it'll never happen ;)

Note how I removed the initial "Balls" structure type name. You don't need it, since you're typedefing "ball" to be that type anyway.
_________________
Do you suppose if I put a signature here, anyone would read it? No? I didn't think so either.