How does CCS C store intermediate variables that are larger than the final storage type? Like this:
Code:
int16 var1;
int16 var2;
var1=(var2*99)/100;
Clearly the result will fit in var1, but does var1 need to be an int32 to store the intermediate result (var*99)? Or is the intermediate result stored on the stack as an int32? Do I need to cast anything?
Sorry for the newb question, I should know this but I cannot remember.
Sydney
Joined: 13 Feb 2009 Posts: 71
Posted: Tue Mar 03, 2009 3:42 pm
Quote:
does var1 need to be an int32 to store the intermediate result (var*99)?
Yes.
Code:
var1=(int32)var2*99/100
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
Posted: Tue Mar 03, 2009 4:30 pm
This behaviour is required by the C standard and not specific to CCS C. An expression gets the type of the "largest" member.
bsturm
Joined: 23 Feb 2009 Posts: 29
Posted: Tue Mar 03, 2009 4:33 pm
Thanks,
I suspected it was that way, but I didn't want to waste a couple of bytes of memory if I didn't have to.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum