cancel
Showing results for 
Search instead for 
Did you mean: 

COSMIC compiler behavior : multiply 16bits

arnaud2
Associate
Posted on April 27, 2010 at 15:54

COSMIC compiler behavior : multiply 16bits

2 REPLIES 2
arnaud2
Associate
Posted on May 17, 2011 at 15:08

I found a workaround in C by casting before to multiply:

rul_Result = (T_ULONG)ruw_Op1 * (T_ULONG)ruw_Op2;

luca239955_stm1_st
Senior II
Posted on May 17, 2011 at 15:08

Hi,

the compiler behaviour is correct: in your first example, the C language requires that the result of 16x16 is 16 (bits) and only afterwards it is converted to long (32 bits) because you assign the result to a long variable.

In your second example (casting), the C would require to promote both operands to long, make a long multiplication (32x32) and then assign the result to the long variable, but the compiler detects a possible optimization (the operands are 16 bits) and therefore performs 16x16=32, that is what you want.

C rules are a bit ''difficult'' when it comes to mixing different types...

Regards,

Luca (Cosmic)