我想知道,当两个整数相乘并且结果为typecast为short且分配为short时,编译器将如何解析它?下面是代码片段在GNU GCC 4.5.3中输入int short to
int a=1,b=2,c;
short x=3,y=4,z;
int p;
short q;
int main()
{
c = a*b; /* Mul two ints and assign to int
[compiler resolves this to __mulsi3()] */
z = x*y; /* Mul two short and assign to short
[compiler resolves this to __mulhi3()] */
p = (x*y); /* Mul two short and assign to int
[compiler resolves this to __mulsi3()] */
q =(short)(a*b); /* Mul two ints typecast to short and assign to short
[compiler resolves this to __mulhi3()] */
return 0;
}
在这里,在情况下q =(short)(a*b);
,应(使用__mulsi3()
)来执行第一两个整数乘法,然后将其分配给短。但在这里并非如此,编译器类型会将a
和b
都设为空格,然后调用__mulhi3()
。
我想知道如何更改gcc源代码[哪个文件],以便我可以达到我的上述要求。
你为什么在乎它生成的指令?它是否产生不正确的结果? –