두 개의 정수가 곱 해져서 결과가 짧아지고 짧게 할당되면 컴파일러는이를 어떻게 해석할까요? 아래의 int 처음 두 곱셈 (__mulsi3()
사용)을 수행 한 다음 단락에 할당되어야 코드 q =(short)(a*b);
의 경우 여기 GNU GCC 4.5.3에서 short 형 캐스팅 int에서
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;
}
니펫이다. 하지만 여기서는 그렇지 않습니다. 컴파일러 유형은
a
과
b
을 모두 캐스팅 한 다음
__mulhi3()
을 호출합니다.
위의 요구 사항을 달성 할 수 있도록 gcc 소스 코드 [변경]을 어떻게 할 수 있는지 알고 싶습니다.
왜 어떤 지침이 생성되는지 신경 써야합니까? 잘못된 결과가 나옵니까? –