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 > variable defined in .h file wont assign to another variable.

#52661 - QuantumDoja - Thu Sep 01, 2005 6:45 pm

Hi, I have a variable defined in a .h file such as

Code:

u16 LevelWidth = 100;


I include this .h file in my main.c file like so

Code:

#include "levels.h"


but when I try and assign the variable defined in the .h file to a variable in my main.c file.....it wont work...nothing gets assigned..

Quote:

myothervar = LevelWidth;


what am I missing? (apart from a decent brain)
_________________
Chris Davis

#52666 - QuantumDoja - Thu Sep 01, 2005 7:14 pm

once again...my brain astounds me.....for some reason i had a lot of vars in my code, ripped half out and it worked....i might have filled up too much ram......but then again.......my rom was only 236kb.......bad coding once again!! doh!
_________________
Chris Davis

#52667 - tepples - Thu Sep 01, 2005 7:20 pm

Were you filling up IWRAM? If so, then perhaps you should move some of your variables out to EWRAM and/or perhaps scale back your design if you want it to be multibootable.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#52669 - poslundc - Thu Sep 01, 2005 7:27 pm

Also: don't but variables in .h files. That's not what header files are for, and you'll be in for a world of hurt once the size of your project grows beyond a few files.

Dan.

#52672 - QuantumDoja - Thu Sep 01, 2005 8:30 pm

um...how to i say put this variable in ewram?
_________________
Chris Davis

#52673 - QuantumDoja - Thu Sep 01, 2005 8:36 pm

i think i just use the code in the beginners faq right?......seems to have worked.
_________________
Chris Davis

#52679 - strager - Thu Sep 01, 2005 9:51 pm

QuantumDoja wrote:
Hi, I have a variable defined in a .h file such as
Code:
u16 LevelWidth = 100;



Ick.
For a header file, it should be written as such:
Code:
extern u16 LevelWidth;

And in your load-level source file (where it would be reasonable to put the variable):
Code:
u16 LevelWidth = 100;


It should give you errors if you mess up with externs.