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.

Beginners > parse error before u16

#112610 - QuantumDoja - Mon Dec 18, 2006 6:17 pm

Im compiling with devkitpro and I have a levels.h file that contains my levels....my code has just started throwing up saying:

parse error before u16 - this is the first line on the page...it was working??

Code:

u16 LevelWidth0_0 = 68;
u16 LevelHeight0_0 = 44;


im including it with
Code:
#include "levels.h"

_________________
Chris Davis

#112611 - kusma - Mon Dec 18, 2006 6:20 pm

the parse error is _before_ u16, so we need to know more to nail out the error. these errors are most common due to classes missing semicolon after their declaration.

#112615 - QuantumDoja - Mon Dec 18, 2006 6:35 pm

Thanks Kusma!!!! :-D yep, In the include file before this file, i was missing a semi-colon, i didnt even think of that....just ripped my project to shreds!!! I wish I had a program to check for things like that! :-D thanks again!!!!!!!
_________________
Chris Davis

#112636 - wintermute - Tue Dec 19, 2006 12:56 am

You might also consider not declaring variables in header files, it's bad karma.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#112639 - tepples - Tue Dec 19, 2006 1:31 am

What wintermute means is that you should do this:
Code:
// levels.c

u16 LevelWidth0_0 = 68;
u16 LevelHeight0_0 = 44;

Code:
//levels.h

#ifndef LEVELS_H
#define LEVELS_H
extern u16 LevelWidth0_0;
extern u16 LevelHeight0_0;
#endif

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#112642 - misterDtD - Tue Dec 19, 2006 2:04 am

I was wondering, why is it better to do it that way?

~DtD

#112643 - DekuTree64 - Tue Dec 19, 2006 3:28 am

misterDtD wrote:
I was wondering, why is it better to do it that way?

If you declare variables in a header directly rather than as extern, then they get declared for every .c file the header is included in, therefore causing linker errors because there are multiple globals with the same name. And if you can only safely include the header in one .c file, then there's no point in it being a header in the first place, rather than just being part of the .c file itself.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku