Error in debugging code
Posted: Thu Jul 30, 2020 9:52 am
IN the middle of implementing a low level BASIC like "Thing"(not sure what to call it, for now I call it executer), when I encountered this error. I was trying to implement negative number support in the code. In the "source code" it executes(not the source of the executer itself) negative numbers are simply number prefixed by a negative sign. My "executer" should convert this into actual negative numbers and store in arrays. There was some problem with that, so I wrote a bunch of debug-print code to check the issue.
In this code I am just printing an integer array to check if it contains the value it should contain..(array should not contain any negative value at this point)
I tried to debug using this code, tried changing lot of stuff, but nothing. Soon I realized that I already fixed the main code but the debug print was actually buggy! It doesn't print exp[0], no matter what I try.For example, when I expect the output to be:
This is my int_to_ascii code:
I don't see a way from these code snippets that it should omit exp[0] or effect exp[1] when value of exp[0] is changed, when actually exp contains all desired values and my main code works. As it's just a debug-prints it's not super important, but still I would like to know the cause of this behavior.
In this code I am just printing an integer array to check if it contains the value it should contain..(array should not contain any negative value at this point)
Code: Select all
int test=0;char val[5]={};
int l=0;
for(int k=0;exp[k]!=0;k++)
{
test=exp[k]; //taking in value
int_to_ascii(test, val); //converting to ASCII
print(val,2*l,0xd); //my print function-takes a pointer, an offset, and a color value
for(int m=0;val[m]!='\0';m++) //clearing out val for next iteration
val[m]='\0';
l=k*0xA0; //next line
}
but it always do
- 20480
20530
5
If I try to force some other value into exp[0], then20530 ;omits the first value
5
20530P\. ;invalid values, there is no way this can happen
5
This is my int_to_ascii code:
Code: Select all
if(src==0)
{
stack[i++]='\0'; //pushing NULL and 0 to stack
stack[i++]='0';
}
else
{
while(src!=0) //converting last digit and pushing to stack
{
stack[i]=(0x30+src%10);
src/=10;
i++;
}
}
i--;
len=i;
while(i>=0)
{
dest[len-i]=stack[i]; //popping and placing from left to right
i--; //inorder not to get reversed.
}