This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Why GCC 4.1.2 casting "short int" to "short unsigned int" ?
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: 梁? <liangkun1983 at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 14 Apr 2009 11:06:29 +0200
- Subject: Re: Why GCC 4.1.2 casting "short int" to "short unsigned int" ?
- References: <f895fcfb0904140020r1ee53f24r6648db0c4e818e89@mail.gmail.com>
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.
> 此致
> 敬礼!
>
> 梁?
>