GCC casts short to int

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a problem with GCC casting my short variables to integers.

My code snippet is:
  short a = 0;
  short b = 0;

  int count;

  for(count = 0; count < cycles; count++, a++, b++)
  {
    c += (short)a * (short)b;
  }

However, the instructions produced by this code (for an ARM processor)
include:
  mla  r1[c], r3[a], r3[b], r1[c]                 (multiply accumulate)

However, this instruction takes 32-bit inputs and so when a and b overflow,
they are treated as integers and not shorts.

Isn't this technically an incorrect compilation of the code, when I
explicitly (and redundantly) cast a and b to shorts?

What I want GCC to do is left-shift, right-shift the values to make sure
that the short variables remain as short variables.

How can I instruct GCC (in the code) to do this?

Thanks in advance!
-- 
View this message in context: http://www.nabble.com/GCC-casts-short-to-int-tp24203223p24203223.html
Sent from the gcc - Help mailing list archive at Nabble.com.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux