HC12: Integer Division of Longs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HC12: Integer Division of Longs

Jump to solution
1,537 Views
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

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
610 Views
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.

View solution in original post

0 Kudos
Reply
1 Reply
611 Views
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 Kudos
Reply