2009/4/14 梁�� <liangkun1...@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. > 此致 > 敬礼! > > 梁�� >