HC12: Integer Division of Longs

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

HC12: Integer Division of Longs

跳至解决方案
1,916 次查看
YeOldeBDM
Contributor III
This may be something I missed in the C standard, but I am not getting the expected result.
 
 
static long temp_long; //static because linker  has SP INFO incorrect warning
 
temp_long=99999;
//snip
//.
//.
//snip
//debugger gives temp_long is 99999 in base 10 right here
temp_long=temp_long+(long)50; 
//debugger gives correct value of 10049 for temp_long
temp_long=temp_long/(long)100;
//debugger says temp_long is now 66536
//thats 1000+65536 which looks like a problem mixing ints and longs
 
What did I miss about integer division of longs in K&R or the C standard?
 
I am using Codewarrior 3.1 for HCS12.
 
 

Message Edited by CrasyCat on 2007-04-13 11:26 AM

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
989 次查看
YeOldeBDM
Contributor III
Never mind: the results became consistent after some code below the lines in question was removed.  Basically the source of mysterious results  was the optimizer looking ahead in the listing and putting some work in the division by 100.

在原帖中查看解决方案

0 项奖励
回复
1 回复
990 次查看
YeOldeBDM
Contributor III
Never mind: the results became consistent after some code below the lines in question was removed.  Basically the source of mysterious results  was the optimizer looking ahead in the listing and putting some work in the division by 100.
0 项奖励
回复