Hi:

我想我遇到一个SDCC关于除法取余运算的BUG。
I think I came across an SDCC bug about the divide operation.

测试代码如下
Test code is as follows:

void modtest2(unsigned int t)
{
        while(t != 0){
                t % 10;
                printf("t = %d, mod10 = %d\r\n", t, t%10);              
                t = t / 10;
        }
}
void mod_test(void)
{
        static unsigned int t = 1000;
        modtest2(t);
}

问题应该是当执行除法运算后,再次执行取模运算,取模得到的结果不正确。
The problem may be that after performing the division operation, the modulo 
operation is performed again, and the result obtained by modulo is incorrect.

以上代码测试结果如下:
the test result is as follows:

t = 2943, mod10 = 3
* t = 294, mod10 = 72
t = 29, mod10 = 9
t = 2, mod10 = 2
t = 2944, mod10 = 4
* t = 294, mod10 = 6
t = 29, mod10 = 9
t = 2, mod10 = 2

* 号标记的行,得到了错误结果
The line marked by "*" is incorrect.

Sorry for my pool English,the English is translated by Google.



_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to