This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why GCC 4.1.2 casting "short int" to "short unsigned int" ?


2009/4/14 梁? <liangkun1983@gmail.com>:
> GCC4.1.2 on a Intel Xeon CPU
> The test program is test.c:
>
> extern int bar(short);
>
> int foo(short arg1, short arg2)
> {
>  short res;
>  res = arg1 + arg2;
>  return bar(res);
> }
>
> Compiled with : gcc -fdump-tree-all -S test.c
> The resulting test.c.t02.original is :
> ;; Function foo (foo)
> ;; enabled by -tree-original
>
> {
>  short int res;
>
>    short int res;
>  res = (short int) ((short unsigned int) arg1 + (short unsigned int) arg2);
>  return bar ((int) res);
> }
>
> So, my question is : why gcc casted "short" to "short unsigned int"
> before addition and casted back after?

This is a question for gcc-help.  The addition is carried out in
integer type and converted back to short.  The result you see
is the result of optimizing this.

Richard.

>                                       此致
> 敬礼!
>
>                                    梁?
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]