#11747 - yaustar - Fri Oct 17, 2003 8:36 pm
Me and a friend are working on a program, and hit a problem. It seems that some of the variables are not being changed or not there at all.
We have been using a fair few s16 variables but we cant seem to find the root of the problem..
help
_________________
[Blog] [Portfolio]
#11748 - sajiimori - Fri Oct 17, 2003 8:48 pm
Well, the gba does have a limited amount of memory...
Maybe you could show us the actual situation you're in, and any errors you've encountered. How many is a "fair amount"? What do you mean by variables that are not there at all?
#11750 - yaustar - Fri Oct 17, 2003 9:39 pm
around 20 s16 values.
Basically it is a waypointing system and the guy moves to thr right x value but the wrong y value.
What is strange though is that it uses the next waypoint's x value for the previous y value instead.
I think some where along the line we overwrote some values in memory.
[/code]
_________________
[Blog] [Portfolio]
#11751 - sajiimori - Fri Oct 17, 2003 10:05 pm
Sounds like a good old-fashioned bug, unrelated to the number of variables. I don't have enough information to help otherwise.
#11752 - yaustar - Fri Oct 17, 2003 10:08 pm
Yeah, it takes 5 mins to code it and 3hrs (still counting) to debug it.
Thanks for the help anyway
_________________
[Blog] [Portfolio]
#11755 - yaustar - Fri Oct 17, 2003 11:43 pm
is there a decent source debugger besides mappy?
_________________
[Blog] [Portfolio]
#11758 - tepples - Sat Oct 18, 2003 12:26 am
If you can get VisualBoyAdvance to work with GDB/Insight (instructions), you can use that.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#11759 - yaustar - Sat Oct 18, 2003 1:13 am
We found the 'error'.
we created the variable as
and started putting values like this
Code: |
array[0][0] =
array[0][1] =
array[1][0] =
array[1][1] =
array[2][0] =
array[2][1] =
|
Anyone else see the flaw here?
Thanks guys anyway. Sorry for being blind :\
_________________
[Blog] [Portfolio]
#11760 - Sean - Sat Oct 18, 2003 3:23 am
yep, your matrix was being declared as 3x1 and you started using it as if it were 3x2. I can admit to having done that a few times.
#11761 - poslundc - Sat Oct 18, 2003 5:07 am
FYI, variables you create are automatically put into IWRAM, and you have 32K of that.
20 s16 variables would consume 40 bytes of memory, or about 0.122% of the internal work memory you have. So you are not in any tremendous immediate danger. :)
When your project gets larger, you can start looking at EWRAM to hold your less speed-critical data. There's 256K there, which should be plenty for most applications.
I'm not certain what happens when you allocate more variables than IWRAM can hold. Does anyone know if the compiler will report a linker error? Or will your program just crash?
Dan.
#11764 - yaustar - Sat Oct 18, 2003 12:29 pm
I am amazed that the compilar didnt pick up on this and check out an error. It's amazing when you have been debugging to find an error for hours and it just appears right in front of you.
_________________
[Blog] [Portfolio]
#11778 - sajiimori - Sat Oct 18, 2003 8:27 pm
C generally assumes you know what you're doing. Here are a few circumstances where what you ask for is nearly impossible.
Here, the compiler cannot know how big the array is because the files are compiled seperately:
Code: |
// file1.c
int array[5];
// file2.c
extern int* array;
f() { array[6] = 100; }
|
Here, the compiler cannot know which values might be passed to alter_array:
Code: |
int array[5];
void alter_array(int element, int value)
{
array[element] = value;
}
|
The compiler doesn't know what input there may be:
Code: |
int array[5];
f()
{
int element;
printf("Which element do you want to be 100?\n");
scanf("%d", &element);
array[element] = 100;
}
|
Sometimes, even if there is sufficient information, it's unrealistic to expect any compiler to deduce that there is a buffer overrun:
Code: |
int array[5];
f()
{
int i;
for(i = 0; i < 10; ++i)
array[i >> 1] = 100;
}
|
The compiler could warn you when you're using a constant indexer on an array of known size, but that's a pretty specific circumstance that wouldn't prevent the majority of errors.