need help for arithmetic conversion about gcc

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

 



Dear all,

I am trying to figure out the rules of arithmetic conversion in gcc.
In my previous understanding, suppose there are two operands with the
different data type, the operand with less integer conversion rank
would be converted to the type of the operand with greater rank. But I
found it does not work like that in gcc. Take the following statements
as an example,

short ilval irval;
long lval;
ilval = lval + irval;

In this case, both lval and ilval are converted to "short unsigned
int", the result of "(short unsigned int) lval+(short unsigned int)
irval" is then converted to "short int". I found the coversion notes
from the RTL codes' file. The corresponding informations is given
below:

;; D.1528 = (short unsigned int) lval
;; irval.0 = (short unsigned int) irval
;; D.1530 = D.1528 + irval.0
;; ilval = (short int) D.1530

The part which confuses me is that the operand "lval" is converted
from a type with greater rank (i.e., long ) to a type with less rank
(i.e., short unsigned int ).

However if it is multiply operation case, like this:

short ilval irval;
long lval;
ilval = lval + irval;

gcc handles it another way:

;; D.1528 = (long int) irval
;; D.1529 = D.1528 * lval
;; ilval = (short int) D.1529

In this case (multiply operation), irval is converted from a type with
less rank (int) to the type with greater rank (long).


I wonder why these two cases are treated differently.
Can anyone help me?
I would be more than happy if you can also give some materials
regarding the arithmetic conversion rules of gcc.

Thank you very much.


[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