COSMIC compiler behavior : multiply 16bits
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2010-04-27 6:54 AM
Posted on April 27, 2010 at 15:54
COSMIC compiler behavior : multiply 16bits
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:08 AM
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;Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:08 AM
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)
